Class: EventMachine::PeriodicTimer

Inherits:
Object
  • Object
show all
Defined in:
lib/em/timers.rb

Overview

Creates a periodic timer

Examples:

n = 0
timer = EventMachine::PeriodicTimer.new(5) do
  puts "the time is #{Time.now}"
  timer.cancel if (n+=1) > 5
end

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (PeriodicTimer) initialize(interval, callback = nil, &block)

Create a new periodic timer that executes every interval seconds



32
33
34
35
36
37
38
# 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

Instance Attribute Details

- (Object) interval

Fire the timer every interval seconds



46
47
48
# File 'lib/em/timers.rb', line 46

def interval
  @interval
end

Instance Method Details

- (Object) cancel

Cancel the periodic timer



41
42
43
# File 'lib/em/timers.rb', line 41

def cancel
  @cancelled = true
end