Class: Phronomy::Runtime::TimerService

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/engine/runtime/timer_service.rb

Overview

Lazy owner of the Runtime's threadless timer queue.

Instance Method Summary collapse

Constructor Details

#initializeTimerService

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

#shutdownObject



29
30
31
# File 'lib/phronomy/engine/runtime/timer_service.rb', line 29

def shutdown
  @mutex.synchronize { @timer&.shutdown }
end

#timer_queueObject



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