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.



1704
1705
1706
1707
1708
# File 'lib/eventmachine.rb', line 1704

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

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



1703
1704
1705
# File 'lib/eventmachine.rb', line 1703

def interval
  @interval
end

Instance Method Details

#cancelObject



1718
1719
1720
# File 'lib/eventmachine.rb', line 1718

def cancel
	@cancelled = true
end

#fireObject



1712
1713
1714
1715
1716
1717
# File 'lib/eventmachine.rb', line 1712

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

#scheduleObject



1709
1710
1711
# File 'lib/eventmachine.rb', line 1709

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