iilyak commented on a change in pull request #2662: Use `couch_rate` application for `couch_view` URL: https://github.com/apache/couchdb/pull/2662#discussion_r393044718
########## File path: src/couch_rate/src/couch_rate.erl ########## @@ -0,0 +1,106 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_rate). + +-include("couch_rate.hrl"). + +-export([ + new/3, + from_map/3, + budget/1, + delay/1, + wait/1, + in/2, + success/2, + failure/1, + is_congestion/1, + min_latency/1, + format/1, + to_map/1, + id/1, + module/1, + state/1 +]). + +-define(LIMITER, ?MODULE). + +-type id() :: term(). +-type state() :: term(). + +-opaque limiter() :: #?LIMITER{}. + +-export_type([ + id/0, + state/0, + limiter/0 +]). + +-spec new(id(), module(), map()) -> couch_rate:limiter(). +new(Id, Module, Options) -> + #?LIMITER{id = Id, module = Module, state = Module:new(Id, Options)}. Review comment: I could use `couch_rate` here instead of `#?LIMITER`. Previously the record was defined in `couch_rate_limiter` module. It was too long to type. Usually in cases when record names are to long and given the fact that record is only used locally. People (on other erlang projects) tend to use `#?MODULE`. I don't like that because `MODULE` has nothing to do with record name. While I did review of passage code I noticed how author solves the same problem (see https://github.com/sile/passage/blob/master/src/passage_span.erl#L83). I stole that idea and use it when it suits. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
