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.



1861
1862
1863
1864
1865
# File 'lib/eventmachine.rb', line 1861

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

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



1860
1861
1862
# File 'lib/eventmachine.rb', line 1860

def interval
  @interval
end

Instance Method Details

#cancelObject



1875
1876
1877
# File 'lib/eventmachine.rb', line 1875

def cancel
	@cancelled = true
end

#fireObject



1869
1870
1871
1872
1873
1874
# File 'lib/eventmachine.rb', line 1869

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

#scheduleObject



1866
1867
1868
# File 'lib/eventmachine.rb', line 1866

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