Class: Rednode::Scheduler::Timer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#callbackObject

Returns the value of attribute callback.



63
64
65
# File 'lib/rednode/timer.rb', line 63

def callback
  @callback
end

#intervalObject

Returns the value of attribute interval.



63
64
65
# File 'lib/rednode/timer.rb', line 63

def interval
  @interval
end

#periodicObject

Returns the value of attribute periodic.



63
64
65
# File 'lib/rednode/timer.rb', line 63

def periodic
  @periodic
end

#runningObject (readonly)

Returns the value of attribute running.



64
65
66
# File 'lib/rednode/timer.rb', line 64

def running
  @running
end

Instance Method Details

#cancelObject



82
83
84
85
# File 'lib/rednode/timer.rb', line 82

def cancel
  @timer.cancel if @timer
  @timer.remove_timer(self)
end

#startObject



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