4 attr_accessor :condition, :at
6 def initialize(condition, interval)
7 self.condition = condition
8 self.at = Time.now.to_i + interval
27 # Start the scheduler loop to handle events
31 @timer = Thread.new do
33 # get the current time
36 # iterate over each event and trigger any that are due
37 @events.each do |event|
46 # sleep until next check
52 # Create and register a new TimerEvent with the given parameters
53 def schedule(condition, interval = condition.interval)
54 @events << TimerEvent.new(condition, interval)
55 @events.sort! { |x, y| x.at <=> y.at }
59 Hub.trigger(event.condition)
62 # Join the timer thread