Class: UringMachine::Actor

Inherits:
Fiber
  • Object
show all
Defined in:
lib/uringmachine/actor.rb

Defined Under Namespace

Classes: Stop

Instance Method Summary collapse

Instance Method Details

#call(response_mailbox, sym, *a, **k) ⇒ Object



47
48
49
50
# File 'lib/uringmachine/actor.rb', line 47

def call(response_mailbox, sym, *a, **k)
  @machine.push @mailbox, [:call, response_mailbox, sym, a, k]
  @machine.shift response_mailbox
end

#cast(sym, *a, **k) ⇒ Object



42
43
44
45
# File 'lib/uringmachine/actor.rb', line 42

def cast(sym, *a, **k)
  @machine.push @mailbox, [:cast, nil, sym, a, k]
  self
end

#run(machine, target, mailbox) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/uringmachine/actor.rb', line 29

def run(machine, target, mailbox)
  @machine = machine
  @target = target
  @mailbox = mailbox
  while (msg = machine.shift(mailbox))
    process_message(msg)
  end
rescue Stop
  # stopped
ensure
  @target.teardown if @target.respond_to?(:teardown)
end

#stopObject



52
53
54
# File 'lib/uringmachine/actor.rb', line 52

def stop
  @machine.schedule(self, Stop.new)
end