Class: Rednode::Process::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/rednode/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#callbackObject

Returns the value of attribute callback.



85
86
87
# File 'lib/rednode/process.rb', line 85

def callback
  @callback
end

Instance Method Details

#cancelObject



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