diff --git a/lib/core/actor.ex b/lib/core/actor.ex index ad38331..e45d2bf 100644 --- a/lib/core/actor.ex +++ b/lib/core/actor.ex @@ -1,18 +1,16 @@ defmodule Scopes.Core.Actor do + require Logger + defp loop(bhv) do receive do msg -> - # IO.puts("receive: #{inspect msg}") + Logger.debug([msg: inspect(msg)]) case msg do {:message, msg} -> bhv.(msg) loop(bhv) - - {:become, bhv_n} -> - loop(bhv_n) - - {:quit} -> - nil + {:become, bhv_n} -> loop(bhv_n) + {:quit} -> nil end end end @@ -21,7 +19,9 @@ defmodule Scopes.Core.Actor do spawn_link(fn -> loop(bhv) end) end - def send(ac, msg) do + def send(ac, msg, delay \\ 0) do + Process.sleep(delay) + #Process.send_after(ac, {:message, msg}, delay) Kernel.send(ac, {:message, msg}) end diff --git a/lib/csys/csys.ex b/lib/csys/csys.ex index 49379ae..d6ed946 100644 --- a/lib/csys/csys.ex +++ b/lib/csys/csys.ex @@ -12,16 +12,16 @@ defmodule Scopes.CSys do Actor.become(self(), fn msg -> process(msg, scope) end) end - def synapse(rcvr, op) do - fn msg -> Actor.send(rcvr, op.(msg)) end - end - - def process(msg, scope) do - proc(scope).(msg, scope) + def synapse(rcvr, op, delay \\ 0) do + fn msg -> Actor.send(rcvr, op.(msg), delay) end end # helper functions + defp process(msg, scope) do + proc(scope).(msg, scope) + end + def state(scope), do: elem(scope, 0) def proc(scope), do: elem(scope, 1) def syns(scope), do: elem(scope, 2) diff --git a/lib/csys/programs.ex b/lib/csys/programs.ex index eed7c3e..43766b2 100644 --- a/lib/csys/programs.ex +++ b/lib/csys/programs.ex @@ -1,7 +1,9 @@ defmodule Scopes.CSys.Programs do - import Scopes.CSys + import Scopes.CSys, only: [ + neuron: 1, update_neuron: 1, synapse: 3, + syns: 1, env: 1 + ] - alias Scopes.CSys alias Scopes.CSys.Environ # programs @@ -23,7 +25,7 @@ defmodule Scopes.CSys.Programs do def std_proc({:parent}, scope) do env = env(scope) - syn = synapse(self(), &Function.identity/1) + syn = synapse(self(), &Function.identity/1, 0) new = neuron({[], Environ.get_stage(env, :basic, :initial), [syn], env}) notify({:created, new}, scope) end @@ -33,7 +35,7 @@ defmodule Scopes.CSys.Programs do #proc = Environ.get_next_stage(env, :basic, :initial) #proc = Environ.get_stage_for(env, :basic, :activate) proc = Environ.get_stage(env, :basic, :active) - CSys.update_neuron({state, proc, syns, env}) + update_neuron({state, proc, syns, env}) end def std_proc(msg, scope) do