Sha256: da409f69e377cc1e99011ac20e18efbdd3becc7fd7b4c1904e5f4c76769659d3
Contents?: true
Size: 614 Bytes
Versions: 2
Compression:
Stored size: 614 Bytes
Contents
require "timeout" module Throttle class Instance def initialize(strategy, polling, timeout) @strategy = strategy @polling = polling @timeout = timeout end 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 def status @strategy.status end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
full_throttle-0.0.3 | lib/throttle/instance.rb |
full_throttle-0.0.1 | lib/throttle/instance.rb |