Class: RBlock::Timer
- Inherits:
-
Object
- Object
- RBlock::Timer
- Defined in:
- lib/rblocks/timer.rb
Overview
RBlock::Timer is a simple Go inspired timer. Usage timer = RBlock::Timer.new(10) timer.wait do
# ... someting once the time is up
end
Constant Summary collapse
- NAME =
"r block timer"
Instance Method Summary collapse
-
#initialize(duration) ⇒ Timer
constructor
Constructs and starts a timer.
-
#wait {|_self| ... } ⇒ Object
Blocks until the timer is done.
Constructor Details
Instance Method Details
#wait {|_self| ... } ⇒ Object
Blocks until the timer is done. Yields self to block if one is given
28 29 30 31 32 |
# File 'lib/rblocks/timer.rb', line 28 def wait done = @ractor.take yield(self) if block_given? done end |