module Cramp::PeriodicTimer

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/cramp/periodic_timer.rb, line 17
def initialize(*)
  super
  @timers = []
end

Private Instance Methods

continue() click to toggle source
Calls superclass method
# File lib/cramp/periodic_timer.rb, line 24
def continue
  super
  start_periodic_timers
end
init_async_body() click to toggle source
Calls superclass method
# File lib/cramp/periodic_timer.rb, line 29
def init_async_body
  super

  if self.class.periodic_timers.any?
    @body.callback { stop_periodic_timers }
    @body.errback { stop_periodic_timers }
  end
end
start_periodic_timers() click to toggle source
# File lib/cramp/periodic_timer.rb, line 38
def start_periodic_timers
  self.class.periodic_timers.each do |method, options|
    @timers << EventMachine::PeriodicTimer.new(options[:every] || 1) { timer_method_wrapper(method) unless @finished }
  end
end
stop_periodic_timers() click to toggle source
# File lib/cramp/periodic_timer.rb, line 44
def stop_periodic_timers
  @timers.each {|t| t.cancel }
end
timer_method_wrapper(method) click to toggle source
# File lib/cramp/periodic_timer.rb, line 48
def timer_method_wrapper(method)
  send(method)
rescue StandardError, LoadError, SyntaxError => exception
  handle_exception(exception)
end