Class: Progress::Beeper

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

Defined Under Namespace

Classes: Restart

Instance Method Summary collapse

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

#restartObject



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

def restart
  @thread.raise Restart
end

#stopObject



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

def stop
  @thread.kill
end