Class: EventMachine::PeriodicTimer
- Inherits:
-
Object
- Object
- EventMachine::PeriodicTimer
- Defined in:
- lib/em/timers.rb
Overview
Creates a periodic timer
Instance Attribute Summary collapse
-
#interval ⇒ Object
Fire the timer every interval seconds.
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancel the periodic timer.
- #fire ⇒ Object
-
#initialize(interval, callback = nil, &block) ⇒ PeriodicTimer
constructor
Create a new periodic timer that executes every interval seconds.
- #schedule ⇒ Object
Constructor Details
#initialize(interval, callback = nil, &block) ⇒ PeriodicTimer
Create a new periodic timer that executes every interval seconds
32 33 34 35 36 37 38 |
# File 'lib/em/timers.rb', line 32 def initialize interval, callback=nil, &block @interval = interval @code = callback || block @cancelled = false @work = method(:fire) schedule end |
Instance Attribute Details
#interval ⇒ Object
Fire the timer every interval seconds
46 47 48 |
# File 'lib/em/timers.rb', line 46 def interval @interval end |
Instance Method Details
#cancel ⇒ Object
Cancel the periodic timer
41 42 43 |
# File 'lib/em/timers.rb', line 41 def cancel @cancelled = true end |
#fire ⇒ Object
54 55 56 57 58 59 |
# File 'lib/em/timers.rb', line 54 def fire unless @cancelled @code.call schedule end end |
#schedule ⇒ Object
49 50 51 |
# File 'lib/em/timers.rb', line 49 def schedule EventMachine::add_timer @interval, @work end |