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_r393296830
########## File path: src/couch_rate/src/couch_rate.erl ########## @@ -0,0 +1,120 @@ +% 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)}. + + +-spec from_map(id(), module(), map()) -> couch_rate:limiter(). +from_map(Id, Module, Map) -> + #?LIMITER{id = Id, module = Module, state = Module:from_map(Map)}. + + +-spec budget(limiter()) -> Budget :: integer(). Review comment: Should I change the spec of all functions which return plane value to return a tuple? In this case it would be: ---------------------------------------------------------------- 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
