Class: Celluloid::Timer
- Inherits:
-
Object
- Object
- Celluloid::Timer
- 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
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#recurring ⇒ Object
readonly
Returns the value of attribute recurring.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#cancel ⇒ Object
Cancel this timer.
-
#fire ⇒ Object
(also: #call)
Fire the block.
-
#initialize(timers, interval, recurring, block) ⇒ Timer
constructor
A new instance of Timer.
-
#reset ⇒ Object
Reset this timer.
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
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
78 79 80 |
# File 'lib/celluloid/timers.rb', line 78 def interval @interval end |
#recurring ⇒ Object (readonly)
Returns the value of attribute recurring.
78 79 80 |
# File 'lib/celluloid/timers.rb', line 78 def recurring @recurring end |
#time ⇒ Object (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 |
#cancel ⇒ Object
Cancel this timer
92 93 94 |
# File 'lib/celluloid/timers.rb', line 92 def cancel @timers.cancel self end |
#fire ⇒ Object 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 |
#reset ⇒ Object
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 |