csys: provide more complex actions: create parent, create child
This commit is contained in:
parent
850ae6ed7b
commit
f000cd2526
2 changed files with 23 additions and 10 deletions
|
|
@ -21,9 +21,8 @@ defmodule Scopes.CSys.Program do
|
|||
def std_proc(msg, scope) do
|
||||
#scope = Process.get(:scope)
|
||||
case msg do
|
||||
{:parent} ->
|
||||
new = create_parent(scope)
|
||||
notify({:created, new}, scope)
|
||||
{:create, :parent} -> create_parent(scope)
|
||||
{:create, :child} -> create_child(scope)
|
||||
_ -> forward(msg, scope) || notify(msg, scope)
|
||||
end
|
||||
end
|
||||
|
|
@ -48,9 +47,21 @@ defmodule Scopes.CSys.Program do
|
|||
|
||||
# step functions
|
||||
|
||||
def create_parent({_state, proc, _syns, env}) do
|
||||
# create_... steps
|
||||
# todo: provide parameters for initial state, proc / stage, op,
|
||||
# depending on state and stage (proc) of self, as well as message, env, ...
|
||||
|
||||
def create_parent(scope={_state, proc, _syns, env}) do
|
||||
syn = synapse(self(), &Function.identity/1, 0)
|
||||
#neuron({[], Environ.get_stage(env, :basic, :initial), [syn], env})
|
||||
neuron({[], proc, [syn], env})
|
||||
new = neuron({[], proc, [syn], env})
|
||||
notify({:created, new}, scope)
|
||||
end
|
||||
|
||||
def create_child (scope={state, proc, syns, env}) do
|
||||
new = neuron({[], proc, [], env})
|
||||
syn = synapse(new, &Function.identity/1, 0)
|
||||
update_neuron({state, proc, [syn | syns], env})
|
||||
notify({:created, new}, scope)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,11 +15,13 @@ defmodule Scopes.CSysTest do
|
|||
zero = CSys.neuron({[], proc, [], env})
|
||||
Actor.send(zero, "Hello Zero!")
|
||||
assert_receive "Hello Zero!"
|
||||
Actor.send(zero, {:parent})
|
||||
assert_receive {:created, new}
|
||||
Actor.send(new, "Hello New!")
|
||||
assert_receive "Hello New!"
|
||||
# assert_receive "Hello New!"
|
||||
Actor.send(zero, {:create, :parent})
|
||||
assert_receive {:created, new1}
|
||||
Actor.send(new1, {:create, :child})
|
||||
assert_receive {:created, _new2}
|
||||
Actor.send(new1, "Hello New1!")
|
||||
assert_receive "Hello New1!"
|
||||
assert_receive "Hello New1!"
|
||||
Process.sleep(50)
|
||||
# Actor.stop(zero)
|
||||
refute_received msg, "unhandled message(s): #{inspect(msg)}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue