Class: Progress::Beeper
- Inherits:
-
Object
- Object
- Progress::Beeper
- Defined in:
- lib/progress/beeper.rb
Defined Under Namespace
Classes: Restart
Instance Method Summary collapse
-
#initialize(time, &block) ⇒ Beeper
constructor
A new instance of Beeper.
- #restart ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(time, &block) ⇒ Beeper
Returns a new instance of Beeper.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/progress/beeper.rb', line 5 def initialize(time, &block) @thread = Thread.new do begin sleep time block.call rescue Restart end redo end end |
Instance Method Details
#restart ⇒ Object
16 17 18 |
# File 'lib/progress/beeper.rb', line 16 def restart @thread.raise Restart end |
#stop ⇒ Object
20 21 22 |
# File 'lib/progress/beeper.rb', line 20 def stop @thread.kill end |