class EventMachine::PeriodicTimer
end
timer.cancel if (n+=1) > 5
puts “the time is #{Time.now}”
timer = EventMachine::PeriodicTimer.new(5) do
n = 0
@example
Creates a periodic timer
def cancel
def cancel @cancelled = true end
def fire
- Private: -
def fire unless @cancelled @code.call schedule end end
def initialize interval, callback=nil, &block
def initialize interval, callback=nil, &block @interval = interval @code = callback || block @cancelled = false @work = method(:fire) schedule end
def schedule
- Private: -
def schedule EventMachine::add_timer @interval, @work end