message handlers: upon change of scope return new bhv, use this for next actor loop

This commit is contained in:
Helmut Merz 2026-07-28 19:46:21 +02:00
parent 311261cd02
commit e6c5eae4a8
4 changed files with 11 additions and 5 deletions

View file

@ -8,8 +8,8 @@ defmodule Scopes.Core.Actor do
Logger.debug([msg: inspect(msg)]) Logger.debug([msg: inspect(msg)])
case msg do case msg do
{:message, msg} -> {:message, msg} ->
bhv.(msg) bhv_n = bhv.(msg)
loop(bhv) loop(bhv_n || bhv)
{:register, reg, name, value} -> {:register, reg, name, value} ->
Registry.register(reg, name, value) Registry.register(reg, name, value)
loop(bhv) loop(bhv)
@ -39,6 +39,7 @@ defmodule Scopes.Core.Actor do
def become(ac, bhv) do def become(ac, bhv) do
Kernel.send(ac, {:become, bhv}) Kernel.send(ac, {:become, bhv})
bhv
end end
def register(ac, reg, name, value \\ []) do def register(ac, reg, name, value \\ []) do

View file

@ -12,7 +12,9 @@ defmodule Scopes.Core do
end end
def update(scope) do 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 end
def synapse(rcvr, op, delay \\ 0) do def synapse(rcvr, op, delay \\ 0) do

View file

@ -37,6 +37,7 @@ defmodule Scopes.Core.Environ do
[:csys, :created | _rest] -> process_created(msg, scope) [:csys, :created | _rest] -> process_created(msg, scope)
_ -> send(Core.env(scope), msg) # forward message to application _ -> send(Core.env(scope), msg) # forward message to application
end end
nil
end end
def process_created(msg, {state, proc, syns, env}) do def process_created(msg, {state, proc, syns, env}) do
@ -49,11 +50,12 @@ defmodule Scopes.Core.Environ do
end end
{step, seq} = List.pop_at(state.init_seq, 0) {step, seq} = List.pop_at(state.init_seq, 0)
state1 = %State{init_seq: seq} state1 = %State{init_seq: seq}
Core.update({state1, proc, syns, env}) n_bhv = Core.update({state1, proc, syns, env})
if step do if step do
Process.sleep(1) Process.sleep(1)
step.() step.()
end end
n_bhv
end end
# accessing cell registry # accessing cell registry

View file

@ -62,7 +62,7 @@ defmodule Scopes.Core.Program do
[:csys, :connect | _rest] -> Core.connect(msg, scope) [:csys, :connect | _rest] -> Core.connect(msg, scope)
[:csys, :create | _rest] -> create(msg, scope) [:csys, :create | _rest] -> create(msg, scope)
#[:csys, :next | _rest] -> next(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 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())) :pred -> Core.send_message(new, ~w(csys connect)a, Map.put(data, :target, self()))
_ -> nil _ -> nil
end end
nil
end end
# synapse operations # synapse operations