Class: EventMachine::PeriodicTimer

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

Overview

TODO, document this

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ PeriodicTimer

Returns a new instance of PeriodicTimer.



1787
1788
1789
1790
1791
# File 'lib/eventmachine.rb', line 1787

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

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



1786
1787
1788
# File 'lib/eventmachine.rb', line 1786

def interval
  @interval
end

Instance Method Details

#cancelObject



1801
1802
1803
# File 'lib/eventmachine.rb', line 1801

def cancel
	@cancelled = true
end

#fireObject



1795
1796
1797
1798
1799
1800
# File 'lib/eventmachine.rb', line 1795

def fire
	unless @cancelled
		@code.call
		schedule
	end
end

#scheduleObject



1792
1793
1794
# File 'lib/eventmachine.rb', line 1792

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