Class: Timers
- Inherits:
-
Object
- Object
- Timers
- Defined in:
- lib/artoo/ext/timers.rb
Overview
monkeypatches for Timers & Timer classes used by Celluloid
Defined Under Namespace
Classes: Timer
Instance Method Summary collapse
- #continue(timer = nil) ⇒ Object
- #continue_all ⇒ Object
-
#initialize ⇒ Timers
constructor
A new instance of Timers.
- #pause(timer = nil) ⇒ Object
- #pause_all ⇒ Object
Constructor Details
#initialize ⇒ Timers
Returns a new instance of Timers.
3 4 5 6 |
# File 'lib/artoo/ext/timers.rb', line 3 def initialize @timers = SortedSet.new @paused_timers = SortedSet.new end |
Instance Method Details
#continue(timer = nil) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/artoo/ext/timers.rb', line 19 def continue(timer = nil) return continue_all if timer.nil? raise TypeError, "not a Timers::Timer" unless timer.is_a? Timers::Timer @paused_timers.delete timer @timers.add timer end |
#continue_all ⇒ Object
26 27 28 |
# File 'lib/artoo/ext/timers.rb', line 26 def continue_all @paused_timers.each {|timer| timer.continue} end |
#pause(timer = nil) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/artoo/ext/timers.rb', line 8 def pause(timer = nil) return pause_all if timer.nil? raise TypeError, "not a Timers::Timer" unless timer.is_a? Timers::Timer @timers.delete timer @paused_timers.add timer end |
#pause_all ⇒ Object
15 16 17 |
# File 'lib/artoo/ext/timers.rb', line 15 def pause_all @timers.each {|timer| timer.pause} end |