Class: Phronomy::Runtime::TimerService
- Inherits:
-
Object
- Object
- Phronomy::Runtime::TimerService
- Defined in:
- lib/phronomy/engine/runtime/timer_service.rb
Overview
Lazy owner of the Runtime's threadless timer queue.
Instance Method Summary collapse
-
#initialize ⇒ TimerService
constructor
A new instance of TimerService.
- #shutdown ⇒ Object
- #timer_queue ⇒ Object
- #wake_with(&block) ⇒ Object
Constructor Details
#initialize ⇒ TimerService
Returns a new instance of TimerService.
7 8 9 10 11 |
# File 'lib/phronomy/engine/runtime/timer_service.rb', line 7 def initialize @mutex = Mutex.new @timer = nil @waker = nil end |
Instance Method Details
#shutdown ⇒ Object
29 30 31 |
# File 'lib/phronomy/engine/runtime/timer_service.rb', line 29 def shutdown @mutex.synchronize { @timer&.shutdown } end |
#timer_queue ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/phronomy/engine/runtime/timer_service.rb', line 13 def timer_queue @mutex.synchronize do @timer ||= TimerQueue.new.tap do |timer| timer.wake_with(&@waker) if @waker end end end |
#wake_with(&block) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/phronomy/engine/runtime/timer_service.rb', line 21 def wake_with(&block) @mutex.synchronize do @waker = block @timer&.wake_with(&block) end self end |