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.



1699
1700
1701
1702
1703
# File 'lib/eventmachine.rb', line 1699

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

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



1698
1699
1700
# File 'lib/eventmachine.rb', line 1698

def interval
  @interval
end

Instance Method Details

#cancelObject



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

def cancel
	@cancelled = true
end

#fireObject



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

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

#scheduleObject



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

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