class StatusChecker::Timer
Public Class Methods
new(interval)
click to toggle source
# File lib/status_checker/timer.rb, line 3 def initialize(interval) raise ArgumentError, "Illegal interval" if interval < 0 extend MonitorMixin @run = nil @th = nil @delay = interval end
Public Instance Methods
start(&handler)
click to toggle source
# File lib/status_checker/timer.rb, line 11 def start(&handler) @run = true @th = Thread.new do t = Time.now while run? t += @delay (handler.call rescue nil) and sleep(t - Time.now) rescue nil end end end
stop()
click to toggle source
# File lib/status_checker/timer.rb, line 23 def stop synchronize do @run = false end @th.join end
Private Instance Methods
run?()
click to toggle source
# File lib/status_checker/timer.rb, line 32 def run? synchronize do @run end end