Class: Progress::Beeper
- Inherits:
-
Object
- Object
- Progress::Beeper
- Defined in:
- lib/progress/beeper.rb
Overview
Repeatedly run block of code after time interval
Instance Method Summary collapse
-
#initialize(time) ⇒ Beeper
constructor
A new instance of Beeper.
- #restart ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(time) ⇒ Beeper
Returns a new instance of Beeper.
4 5 6 7 8 9 10 11 12 |
# File 'lib/progress/beeper.rb', line 4 def initialize(time) @thread = Thread.new do loop do @skip = false sleep time yield unless @skip end end end |
Instance Method Details
#restart ⇒ Object
14 15 16 17 |
# File 'lib/progress/beeper.rb', line 14 def restart @skip = true @thread.run end |
#stop ⇒ Object
19 20 21 |
# File 'lib/progress/beeper.rb', line 19 def stop @thread.kill end |