Class: Timers::Wait
- Inherits:
-
Object
- Object
- Timers::Wait
- Defined in:
- lib/timers/wait.rb
Overview
An exclusive, monotonic timeout class.
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#remaining ⇒ Object
readonly
Returns the value of attribute remaining.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(duration) ⇒ Wait
constructor
A new instance of Wait.
-
#while_time_remaining ⇒ Object
Yields while time remains for work to be done:.
Constructor Details
#initialize(duration) ⇒ Wait
Returns a new instance of Wait.
27 28 29 30 |
# File 'lib/timers/wait.rb', line 27 def initialize(duration) @duration = duration @remaining = true end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
32 33 34 |
# File 'lib/timers/wait.rb', line 32 def duration @duration end |
#remaining ⇒ Object (readonly)
Returns the value of attribute remaining.
33 34 35 |
# File 'lib/timers/wait.rb', line 33 def remaining @remaining end |
Class Method Details
.for(duration, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/timers/wait.rb', line 14 def self.for(duration, &block) if duration timeout = new(duration) timeout.while_time_remaining(&block) else # If there is no "duration" to wait for, we wait forever. loop do yield(nil) end end end |