Class: Rednode::Scheduler::Timer
- Inherits:
-
Object
- Object
- Rednode::Scheduler::Timer
- Defined in:
- lib/rednode/timer.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(timer) ⇒ Timer
constructor
A new instance of Timer.
- #start ⇒ Object
Constructor Details
#initialize(timer) ⇒ Timer
Returns a new instance of Timer.
66 67 68 69 70 71 72 |
# File 'lib/rednode/timer.rb', line 66 def initialize(timer) @interval = 0 @periodic = false @callback = nil @timer = timer @running = false end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
63 64 65 |
# File 'lib/rednode/timer.rb', line 63 def callback @callback end |
#interval ⇒ Object
Returns the value of attribute interval.
63 64 65 |
# File 'lib/rednode/timer.rb', line 63 def interval @interval end |
#periodic ⇒ Object
Returns the value of attribute periodic.
63 64 65 |
# File 'lib/rednode/timer.rb', line 63 def periodic @periodic end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
64 65 66 |
# File 'lib/rednode/timer.rb', line 64 def running @running end |
Instance Method Details
#cancel ⇒ Object
82 83 84 85 |
# File 'lib/rednode/timer.rb', line 82 def cancel @timer.cancel if @timer @timer.remove_timer(self) end |
#start ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/rednode/timer.rb', line 74 def start @running = true EventMachine.add_timer(@interval.to_f / 1000) do @callback.call @timer.remove_timer(self) end end |