Class: Phronomy::Runtime::TimerService Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Lazy-initialised timer service for a Phronomy::Runtime instance.

Returns a SchedulerTimerAdapter when the backing scheduler is a DeterministicScheduler (enabling virtual-time integration for the :fiber backend), or a standard TimerQueue (OS-thread backed) for all other schedulers.

Instance Method Summary collapse

Constructor Details

#initialize(scheduler) ⇒ TimerService

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TimerService.

Parameters:



15
16
17
18
19
# File 'lib/phronomy/runtime/timer_service.rb', line 15

def initialize(scheduler)
  @scheduler = scheduler
  @mutex = Mutex.new
  @timer = nil
end

Instance Method Details

#shutdownvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Shuts down the timer queue if it was started.



37
38
39
# File 'lib/phronomy/runtime/timer_service.rb', line 37

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

#timer_queueTimerQueue, SchedulerTimerAdapter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns (or lazily creates) the timer queue for this runtime.



24
25
26
27
28
29
30
31
32
# File 'lib/phronomy/runtime/timer_service.rb', line 24

def timer_queue
  @mutex.synchronize do
    @timer ||= if @scheduler.is_a?(DeterministicScheduler)
      SchedulerTimerAdapter.new(@scheduler)
    else
      TimerQueue.new
    end
  end
end