class EventMachine::PeriodicTimer
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
Attributes
Fire the timer every interval seconds
Public Class Methods
Source
# 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
Create a new periodic timer that executes every interval seconds
Public Instance Methods
Source
# File lib/em/timers.rb, line 41 def cancel @cancelled = true end
Cancel the periodic timer
Source
# File lib/em/timers.rb, line 54 def fire unless @cancelled @code.call schedule end end
@private
Source
# File lib/em/timers.rb, line 49 def schedule EventMachine::add_timer @interval, @work end
@private