Class: Wakame::Scheduler::SequenceTimer

Inherits:
EM::PeriodicTimer
  • Object
show all
Includes:
Observable
Defined in:
lib/wakame/scheduler.rb

Instance Method Summary collapse

Constructor Details

#initialize(seq) ⇒ SequenceTimer

Returns a new instance of SequenceTimer.



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/wakame/scheduler.rb', line 227

def initialize(seq)
  @sequence = seq
  super(0) {
    tnow = Time.now
    v = @sequence.value_at(tnow)
    self.changed
    self.notify_observers(v)

    ev = @sequence.next_event(tnow)
    if ev.nil?
      # Terminate this time when it runs out the event to be processed
      Wakame.log.debug("#{self.class}: Quit the timer.")
      cancel
    else
      @interval = ev[0]
      Wakame.log.debug("#{tnow + ev[0]} - #{tnow}(offset sec=#{ev[0]}) : #{ev[1]}")
    end
  }
end