Class: Dynflow::Clock

Inherits:
Actor
  • Object
show all
Includes:
Algebrick::Types
Defined in:
lib/dynflow/clock.rb

Defined Under Namespace

Modules: Timer

Instance Method Summary collapse

Methods inherited from Actor

#behaviour_definition, #finish_termination, #start_termination, #terminating?

Methods included from MethodicActor

#on_message

Methods included from Actor::LogWithFullBacktrace

#log

Constructor Details

#initialize(logger = nil) ⇒ Clock

Returns a new instance of Clock.



43
44
45
46
# File 'lib/dynflow/clock.rb', line 43

def initialize(logger = nil)
  @logger = logger
  @timers = Utils::PriorityQueue.new { |a, b| b <=> a }
end

Instance Method Details

#add_timer(timer) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/dynflow/clock.rb', line 61

def add_timer(timer)
  @timers.push timer
  if @timers.size == 1
    sleep_to timer
  else
    wakeup if timer == first_timer
  end
end

#default_reference_classObject



48
49
50
# File 'lib/dynflow/clock.rb', line 48

def default_reference_class
  ClockReference
end

#on_event(event) ⇒ Object



52
53
54
# File 'lib/dynflow/clock.rb', line 52

def on_event(event)
  wakeup if event == :terminated
end

#tickObject



56
57
58
59
# File 'lib/dynflow/clock.rb', line 56

def tick
  run_ready_timers
  sleep_to first_timer
end