Class: EventMachine::Timer
- Inherits:
-
Object
- Object
- EventMachine::Timer
- Defined in:
- lib/em/timers.rb
Overview
Creates a one-time timer
timer = EventMachine::Timer.new(5) do # this will never fire because we cancel it end timer.cancel
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancel the timer.
-
#initialize(interval, callback = nil, &block) ⇒ Timer
constructor
Create a new timer that fires after a given number of seconds.
Constructor Details
#initialize(interval, callback = nil, &block) ⇒ Timer
Create a new timer that fires after a given number of seconds
11 12 13 |
# File 'lib/em/timers.rb', line 11 def initialize interval, callback=nil, &block @signature = EventMachine::add_timer(interval, callback || block) end |
Instance Method Details
#cancel ⇒ Object
Cancel the timer
16 17 18 |
# File 'lib/em/timers.rb', line 16 def cancel EventMachine.send :cancel_timer, @signature end |