Method: Actor::Mixins#add

Defined in:
lib/Olib/actor/actor.rb

#add(state, &callback) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/Olib/actor/actor.rb', line 89

def add(state, &callback)
  ref = self

  states << state.to_sym
  supervisor.add(state) do
    Fiber.yield until ref.is?(state)
    ref.history << state
    garbage_collect!
    pre_hooks.each do |hook| hook.call(ref) end
    # did a pre_hook prempt this op?
    if ref.is?(state)
      callback.call(ref)
      post_hooks.each do |hook| hook.call(ref) end
    end
  end
  self
end