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.



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

#restartObject



14
15
16
17
# File 'lib/progress/beeper.rb', line 14

def restart
  @skip = true
  @thread.run
end

#stopObject



19
20
21
# File 'lib/progress/beeper.rb', line 19

def stop
  @thread.kill
end