Class: Spade::Runtime::Reactor::Timer
- Inherits:
-
Object
- Object
- Spade::Runtime::Reactor::Timer
- Defined in:
- lib/spade/runtime/reactor.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#periodic ⇒ Object
Returns the value of attribute periodic.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(reactor) ⇒ Timer
constructor
A new instance of Timer.
- #start ⇒ Object
Constructor Details
#initialize(reactor) ⇒ Timer
Returns a new instance of Timer.
124 125 126 127 128 129 130 |
# File 'lib/spade/runtime/reactor.rb', line 124 def initialize(reactor) @interval = 0 @periodic = false @callback = nil @reactor = reactor @running = false end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
121 122 123 |
# File 'lib/spade/runtime/reactor.rb', line 121 def callback @callback end |
#interval ⇒ Object
Returns the value of attribute interval.
121 122 123 |
# File 'lib/spade/runtime/reactor.rb', line 121 def interval @interval end |
#periodic ⇒ Object
Returns the value of attribute periodic.
121 122 123 |
# File 'lib/spade/runtime/reactor.rb', line 121 def periodic @periodic end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
122 123 124 |
# File 'lib/spade/runtime/reactor.rb', line 122 def running @running end |
Instance Method Details
#cancel ⇒ Object
147 148 149 150 151 |
# File 'lib/spade/runtime/reactor.rb', line 147 def cancel EventMachine.cancel_timer(@timer) if @timer @timer = nil @reactor.remove_timer(self) end |
#start ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/spade/runtime/reactor.rb', line 132 def start @running = true if @periodic @timer = EventMachine.add_periodic_timer(@interval.to_f / 1000) do @callback.call end else @timer = EventMachine.add_timer(@interval.to_f / 1000) do @callback.call @timer = nil @reactor.remove_timer(self) end end end |