Method: EventMachine.add_periodic_timer

Defined in:
lib/eventmachine.rb

.add_periodic_timer(*args, &block) ⇒ Object

Adds a periodic timer to the event loop. It takes the same parameters as the one-shot timer method, add_timer. This method schedules execution of the given block repeatedly, at intervals of time at least as great as the number of seconds given in the first parameter to the call.

Examples:

Write a dollar-sign to stderr every five seconds, without blocking


EventMachine.run {
  EventMachine.add_periodic_timer(5) { $stderr.write "$" }
}

Parameters:

  • delay (Integer)

    Delay in seconds

See Also:



352
353
354
355
356
357
# File 'lib/eventmachine.rb', line 352

def self.add_periodic_timer *args, &block
  interval = args.shift
  code = args.shift || block

  EventMachine::PeriodicTimer.new(interval, code)
end