Class: Einhorn::Event::Timer
- Inherits:
-
Object
- Object
- Einhorn::Event::Timer
- Defined in:
- lib/einhorn/event/timer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
-
.open(*args, &blk) ⇒ Object
TODO: abstract into some interface.
Instance Method Summary collapse
- #deregister! ⇒ Object
- #expires_at ⇒ Object
-
#initialize(time, start = nil, &blk) ⇒ Timer
constructor
A new instance of Timer.
- #register! ⇒ Object
- #ring! ⇒ Object
Constructor Details
#initialize(time, start = nil, &blk) ⇒ Timer
Returns a new instance of Timer.
5 6 7 8 9 |
# File 'lib/einhorn/event/timer.rb', line 5 def initialize(time, start=nil, &blk) @time = time @start = start || Time.now @blk = blk end |
Instance Attribute Details
#time ⇒ Object (readonly)
Returns the value of attribute time.
3 4 5 |
# File 'lib/einhorn/event/timer.rb', line 3 def time @time end |
Class Method Details
.open(*args, &blk) ⇒ Object
TODO: abstract into some interface
12 13 14 15 16 |
# File 'lib/einhorn/event/timer.rb', line 12 def self.open(*args, &blk) instance = self.new(*args, &blk) instance.register! instance end |
Instance Method Details
#deregister! ⇒ Object
34 35 36 37 |
# File 'lib/einhorn/event/timer.rb', line 34 def deregister! Einhorn.log_debug("Nuking timer that expired #{Time.now - self.expires_at}s ago") Einhorn::Event.deregister_timer(self) end |
#expires_at ⇒ Object
18 19 20 |
# File 'lib/einhorn/event/timer.rb', line 18 def expires_at @start + @time end |
#register! ⇒ Object
29 30 31 32 |
# File 'lib/einhorn/event/timer.rb', line 29 def register! Einhorn.log_debug("Scheduling a new #{self.time}s timer") Einhorn::Event.register_timer(self) end |