class PeriodicScheduler::Event

Attributes

callback[R]
keep[R]
period[R]
quantum_period[R]

Public Class Methods

new(quantized_space, now, period, keep, &callback) click to toggle source
# File lib/periodic-scheduler.rb, line 30
def initialize(quantized_space, now, period, keep, &callback)
                    @quantized_space = quantized_space
  @period = period
                    @run_time = now + period
  @keep = keep
  @callback = callback
                    quantatize(@run_time)
end

Public Instance Methods

call() click to toggle source
# File lib/periodic-scheduler.rb, line 71
def call
  @callback.call
end
keep?() click to toggle source
# File lib/periodic-scheduler.rb, line 53
def keep?
        @keep
end
reschedule(qnow) click to toggle source
# File lib/periodic-scheduler.rb, line 39
def reschedule(qnow)
        # keep rescheduling until we get it scheduled in future quant
        until @quantum_period > qnow
                @run_time += @period
                quantatize(@run_time)
        end

        @reschedule_hook.call(self) if @reschedule_hook
end
reschedule_hook(&callback) click to toggle source
# File lib/periodic-scheduler.rb, line 49
def reschedule_hook(&callback)
        @reschedule_hook = callback
end
stop() click to toggle source
# File lib/periodic-scheduler.rb, line 57
def stop
        return if @stopped
        @stopped = true
        @stop_hook.call(self) if @reschedule_hook
end
stop_hook(&callback) click to toggle source
# File lib/periodic-scheduler.rb, line 67
def stop_hook(&callback)
        @stop_hook = callback
end
stopped?() click to toggle source
# File lib/periodic-scheduler.rb, line 63
def stopped?
        @stopped
end

Private Instance Methods

quantatize(period) click to toggle source
# File lib/periodic-scheduler.rb, line 77
def quantatize(period)
        @quantum_period = @quantized_space.project(period)
end