Class: Rednode::Process::Timer
- Inherits:
-
Object
- Object
- Rednode::Process::Timer
- Defined in:
- lib/rednode/process.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(process) ⇒ Timer
constructor
A new instance of Timer.
- #start(start, interval) ⇒ Object
Constructor Details
#initialize(process) ⇒ Timer
Returns a new instance of Timer.
87 88 89 90 |
# File 'lib/rednode/process.rb', line 87 def initialize(process) @process = process @timer = nil end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
85 86 87 |
# File 'lib/rednode/process.rb', line 85 def callback @callback end |
Instance Method Details
#cancel ⇒ Object
100 101 102 |
# File 'lib/rednode/process.rb', line 100 def cancel @process.scheduler.cancel_timer(@timer) end |
#start(start, interval) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/rednode/process.rb', line 92 def start(start, interval) if interval == 0 @timer = @process.scheduler.add_timer(start) { callback.call } else @timer = @process.scheduler.add_periodic_timer(start) { callback.call } end end |