Class: EventMachine::PeriodicTimer

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

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ PeriodicTimer

Returns a new instance of PeriodicTimer.



1116
1117
1118
1119
1120
# File 'lib/eventmachine.rb', line 1116

def initialize *args, &block
	@interval = args.shift
	@code = args.shift || block
	schedule
end

Instance Method Details

#cancelObject



1128
1129
1130
# File 'lib/eventmachine.rb', line 1128

def cancel
	@cancelled = true
end

#fireObject



1124
1125
1126
1127
# File 'lib/eventmachine.rb', line 1124

def fire
	@code.call
	schedule unless @cancelled
end

#scheduleObject



1121
1122
1123
# File 'lib/eventmachine.rb', line 1121

def schedule
	EventMachine::add_timer @interval, proc {self.fire}
end