Class: ModSpox::Monitors::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/mod_spox/Monitors.rb

Overview

The Timer is a time based monitor (thus the “Timer” part of the name)

Instance Method Summary collapse

Constructor Details

#initializeTimer

Create a new Timer Monitor



9
10
11
# File 'lib/mod_spox/Monitors.rb', line 9

def initialize
    @threads = Array.new
end

Instance Method Details

#wait(time = nil) ⇒ Object

How long the monitor should wait



26
27
28
29
30
31
32
33
# File 'lib/mod_spox/Monitors.rb', line 26

def wait(time=nil)
    @threads << Thread.current
    if(time.nil?)
        sleep
    else
        sleep(time)
    end
end

#wakeupObject

Force the monitor to wake everyone up



14
15
16
17
18
19
20
21
22
23
# File 'lib/mod_spox/Monitors.rb', line 14

def wakeup
    @threads.each do |t|
        begin
            t.wakeup
        rescue Object => boom
            # thread was dead #
        end
    end
    @threads.clear
end