class Throttle::Instance
Public Class Methods
new(strategy, polling, timeout)
click to toggle source
# File lib/throttle/instance.rb, line 5 def initialize(strategy, polling, timeout) @strategy = strategy @polling = polling @timeout = timeout end
Public Instance Methods
limit() { |count, time| ... }
click to toggle source
# File lib/throttle/instance.rb, line 11 def limit(&block) timeout(@timeout) do loop do go, count, time = @strategy.acquire if go return yield(count, time) if block.arity > 0 return yield end sleep @polling end end rescue Timeout::Error raise Throttle::ThrottledError, "can't execute at this time" end
status()
click to toggle source
# File lib/throttle/instance.rb, line 27 def status @strategy.status end