Class: Dynflow::Clock

Inherits:
MicroActor show all
Includes:
Algebrick::Types
Defined in:
lib/dynflow/clock.rb

Defined Under Namespace

Modules: Timer

Constant Summary collapse

Tick =
Algebrick.atom
Pills =
Algebrick.type do
  variants None = atom,
           Took = atom,
           Pill = type { fields Float }
end

Constants inherited from MicroActor

MicroActor::Terminate

Instance Attribute Summary

Attributes inherited from MicroActor

#initialized, #logger

Instance Method Summary collapse

Methods inherited from MicroActor

#<<, #ask, #initialize, #stopped?

Constructor Details

This class inherits a constructor from Dynflow::MicroActor

Instance Method Details

#ping(who, time, with_what = nil, where = :<<) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dynflow/clock.rb', line 43

def ping(who, time, with_what = nil, where = :<<)
  Type! time, Time, Numeric
  time  = Time.now + time if time.is_a? Numeric
  timer = Timer[who, time, with_what.nil? ? Algebrick::Types::None : Some[Object][with_what], where]
  if terminated?
    Thread.new do
      sleep [timer.when - Time.now, 0].max
      timer.apply
    end
  else
    self << timer
  end
end