Class: YamWow::Throttle
- Inherits:
-
Object
- Object
- YamWow::Throttle
- Defined in:
- lib/yamwow/throttle.rb
Instance Method Summary collapse
-
#initialize(max_requests, duration_in_seconds) ⇒ Throttle
constructor
A new instance of Throttle.
- #when_ready ⇒ Object
Constructor Details
#initialize(max_requests, duration_in_seconds) ⇒ Throttle
Returns a new instance of Throttle.
4 5 6 7 8 |
# File 'lib/yamwow/throttle.rb', line 4 def initialize(max_requests, duration_in_seconds) @request_log = [] @max_requests = max_requests @duration_in_seconds = duration_in_seconds end |
Instance Method Details
#when_ready ⇒ Object
10 11 12 13 14 |
# File 'lib/yamwow/throttle.rb', line 10 def when_ready sleep_if_limit_reached @request_log << Time.now yield end |