module Actor::Mixins

Public Instance Methods

add(state, &callback) click to toggle source
# 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
after_every(&hook) click to toggle source
# File lib/Olib/actor/actor.rb, line 84
def after_every(&hook)
  post_hooks << hook
  self
end
before_every(&hook) click to toggle source
# File lib/Olib/actor/actor.rb, line 79
def before_every(&hook)
  pre_hooks << hook
  self
end
emit(state) click to toggle source
# File lib/Olib/actor/actor.rb, line 46
def emit(state)
  state = state.to_sym
  validate! state
  self
end
garbage_collect!() click to toggle source
# File lib/Olib/actor/actor.rb, line 75
def garbage_collect!
  history.shift while history.size > states.size
end
history() click to toggle source
# File lib/Olib/actor/actor.rb, line 30
def history
  self.class_variable_get(:@@history)
end
is?(state) click to toggle source
# File lib/Olib/actor/actor.rb, line 61
def is?(state)
  validate!(state)
  state == state
end
last() click to toggle source
# File lib/Olib/actor/actor.rb, line 66
def last
  history[-2]
end
post_hooks() click to toggle source
# File lib/Olib/actor/actor.rb, line 22
def post_hooks
  self.class_variable_get(:@@post_hooks)
end
pre_hooks() click to toggle source
# File lib/Olib/actor/actor.rb, line 18
def pre_hooks
  self.class_variable_get(:@@pre_hooks)
end
start(state) click to toggle source
# File lib/Olib/actor/actor.rb, line 42
def start(state)
  class_variable_set(:@@state, state.to_sym)
end
state() click to toggle source
# File lib/Olib/actor/actor.rb, line 26
def state
  self.class_variable_get(:@@state)
end
state=(state) click to toggle source
# File lib/Olib/actor/actor.rb, line 38
def state=(state)
  class_variable_set(:@@state, state.to_sym)
end
states() click to toggle source
# File lib/Olib/actor/actor.rb, line 14
def states
  self.class_variable_get(:@@states)
end
supervisor() click to toggle source
# File lib/Olib/actor/actor.rb, line 34
def supervisor
  self.class_variable_get(:@@supervisor)
end
to_s() click to toggle source
# File lib/Olib/actor/actor.rb, line 52
def to_s
  "#{self.name}<state=#{state} last=#{last} history=#{history} states=#{states}>"
end
validate!(state) click to toggle source
# File lib/Olib/actor/actor.rb, line 70
def validate!(state)
  state = state.to_sym
  raise Actor::InvalidState.new(state, self) unless states.include?(state)
end
yield(state) click to toggle source
# File lib/Olib/actor/actor.rb, line 56
def yield(state)
  emit(state)
  Fiber.yield
end