From e6c5eae4a8057b76869195c6ba10e655df8e449e Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Tue, 28 Jul 2026 19:46:21 +0200 Subject: [PATCH] message handlers: upon change of scope return new bhv, use this for next actor loop --- lib/core/actor.ex | 5 +++-- lib/core/core.ex | 4 +++- lib/core/environ.ex | 4 +++- lib/core/program.ex | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/core/actor.ex b/lib/core/actor.ex index 2262d95..24bffbf 100644 --- a/lib/core/actor.ex +++ b/lib/core/actor.ex @@ -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 diff --git a/lib/core/core.ex b/lib/core/core.ex index 1f1ad68..1fe0395 100644 --- a/lib/core/core.ex +++ b/lib/core/core.ex @@ -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 diff --git a/lib/core/environ.ex b/lib/core/environ.ex index d910d2d..101c700 100644 --- a/lib/core/environ.ex +++ b/lib/core/environ.ex @@ -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 diff --git a/lib/core/program.ex b/lib/core/program.ex index e7a7a71..23df7a0 100644 --- a/lib/core/program.ex +++ b/lib/core/program.ex @@ -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