message handlers: upon change of scope return new bhv, use this for next actor loop
This commit is contained in:
parent
311261cd02
commit
e6c5eae4a8
4 changed files with 11 additions and 5 deletions
|
|
@ -8,8 +8,8 @@ defmodule Scopes.Core.Actor do
|
|||
Logger.debug([msg: inspect(msg)])
|
||||
case msg do
|
||||
{:message, msg} ->
|
||||
bhv.(msg)
|
||||
loop(bhv)
|
||||
bhv_n = bhv.(msg)
|
||||
loop(bhv_n || bhv)
|
||||
{:register, reg, name, value} ->
|
||||
Registry.register(reg, name, value)
|
||||
loop(bhv)
|
||||
|
|
@ -39,6 +39,7 @@ defmodule Scopes.Core.Actor do
|
|||
|
||||
def become(ac, bhv) do
|
||||
Kernel.send(ac, {:become, bhv})
|
||||
bhv
|
||||
end
|
||||
|
||||
def register(ac, reg, name, value \\ []) do
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ defmodule Scopes.Core do
|
|||
end
|
||||
|
||||
def update(scope) do
|
||||
Actor.become(self(), fn msg -> process(msg, scope) end)
|
||||
bhv_n = fn msg -> process(msg, scope) end
|
||||
Actor.become(self(), bhv_n)
|
||||
bhv_n
|
||||
end
|
||||
|
||||
def synapse(rcvr, op, delay \\ 0) do
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ defmodule Scopes.Core.Environ do
|
|||
[:csys, :created | _rest] -> process_created(msg, scope)
|
||||
_ -> send(Core.env(scope), msg) # forward message to application
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def process_created(msg, {state, proc, syns, env}) do
|
||||
|
|
@ -49,11 +50,12 @@ defmodule Scopes.Core.Environ do
|
|||
end
|
||||
{step, seq} = List.pop_at(state.init_seq, 0)
|
||||
state1 = %State{init_seq: seq}
|
||||
Core.update({state1, proc, syns, env})
|
||||
n_bhv = Core.update({state1, proc, syns, env})
|
||||
if step do
|
||||
Process.sleep(1)
|
||||
step.()
|
||||
end
|
||||
n_bhv
|
||||
end
|
||||
|
||||
# accessing cell registry
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ defmodule Scopes.Core.Program do
|
|||
[:csys, :connect | _rest] -> Core.connect(msg, scope)
|
||||
[:csys, :create | _rest] -> create(msg, scope)
|
||||
#[:csys, :next | _rest] -> next(msg, scope)
|
||||
_ -> Core.forward(msg, scope) || Core.notify(msg, scope)
|
||||
_ -> Core.forward(msg, scope) || Core.notify(msg, scope); nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -98,6 +98,7 @@ defmodule Scopes.Core.Program do
|
|||
:pred -> Core.send_message(new, ~w(csys connect)a, Map.put(data, :target, self()))
|
||||
_ -> nil
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
# synapse operations
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue