Class: Celluloid::Timer

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/celluloid/timers.rb

Overview

An individual timer set to fire a given proc at a given time

Constant Summary collapse

QUANTUM =

The timer system is guaranteed (at least by the specs) to be this precise during normal operation. Long blocking calls within actors will delay the firing of timers

0.02

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timers, interval, recurring, block) ⇒ Timer

Returns a new instance of Timer.



80
81
82
83
84
85
# File 'lib/celluloid/timers.rb', line 80

def initialize(timers, interval, recurring, block)
  @timers, @interval, @recurring = timers, interval, recurring
  @block = block

  reset
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



78
79
80
# File 'lib/celluloid/timers.rb', line 78

def interval
  @interval
end

#recurringObject (readonly)

Returns the value of attribute recurring.



78
79
80
# File 'lib/celluloid/timers.rb', line 78

def recurring
  @recurring
end

#timeObject (readonly)

Returns the value of attribute time.



78
79
80
# File 'lib/celluloid/timers.rb', line 78

def time
  @time
end

Instance Method Details

#<=>(other) ⇒ Object



87
88
89
# File 'lib/celluloid/timers.rb', line 87

def <=>(other)
  @time <=> other.time
end

#cancelObject

Cancel this timer



92
93
94
# File 'lib/celluloid/timers.rb', line 92

def cancel
  @timers.cancel self
end

#fireObject Also known as: call

Fire the block



104
105
106
107
# File 'lib/celluloid/timers.rb', line 104

def fire
  reset if recurring
  @block.call
end

#resetObject

Reset this timer



97
98
99
100
101
# File 'lib/celluloid/timers.rb', line 97

def reset
  @timers.cancel self if defined?(@time)
  @time = Time.now + @interval
  @timers.insert self
end