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.
6 7 8 9 10 11 12 13 14 |
# File 'lib/progress/beeper.rb', line 6 def initialize(time) @thread = Thread.new do loop do @skip = false sleep time yield unless @skip end end end |
Instance Method Details
#restart ⇒ Object
16 17 18 19 |
# File 'lib/progress/beeper.rb', line 16 def restart @skip = true @thread.run end |
#stop ⇒ Object
21 22 23 |
# File 'lib/progress/beeper.rb', line 21 def stop @thread.kill end |