Class: Lackie::Poller
- Inherits:
-
Object
- Object
- Lackie::Poller
- Defined in:
- lib/lackie/poller.rb
Instance Method Summary collapse
- #await(outcome, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Poller
constructor
A new instance of Poller.
Constructor Details
#initialize(options = {}) ⇒ Poller
Returns a new instance of Poller.
3 4 5 6 7 |
# File 'lib/lackie/poller.rb', line 3 def initialize(={}) @timeout_seconds = .delete(:timeout_seconds) || 3 @interval_seconds = .delete(:interval_seconds) || 0.2 @sleeper = .delete(:sleeper) || Kernel end |
Instance Method Details
#await(outcome, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lackie/poller.rb', line 9 def await(outcome, ={}) seconds_waited = 0 timeout_seconds = [:timeout_seconds] || @timeout_seconds while seconds_waited <= timeout_seconds return if yield @sleeper.sleep @interval_seconds seconds_waited += @interval_seconds end raise TimeoutError.new("Timed out after #{timeout_seconds} seconds awaiting #{outcome}") end |