Class: Progress::Beeper

Inherits:
Object
  • Object
show all
Defined in:
lib/progress/beeper.rb

Overview

Repeatedly run block of code after time interval

Instance Method Summary collapse

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

#restartObject



16
17
18
19
# File 'lib/progress/beeper.rb', line 16

def restart
  @skip = true
  @thread.run
end

#stopObject



21
22
23
# File 'lib/progress/beeper.rb', line 21

def stop
  @thread.kill
end