Creates a periodic timer
@example
n = 0 timer = EventMachine::PeriodicTimer.new(5) do puts "the time is #{Time.now}" timer.cancel if (n+=1) > 5 end
Fire the timer every interval seconds
Create a new periodic timer that executes every interval seconds
# File lib/em/timers.rb, line 32 def initialize interval, callback=nil, &block @interval = interval @code = callback || block @cancelled = false @work = method(:fire) schedule end
Cancel the periodic timer
# File lib/em/timers.rb, line 41 def cancel @cancelled = true end
@private
# File lib/em/timers.rb, line 54 def fire unless @cancelled @code.call schedule end end
@private
# File lib/em/timers.rb, line 49 def schedule EventMachine::add_timer @interval, @work end