when I do this
jon@arch:~/bridge$ iex --sname one -S mix
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.6.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(one@arch)1> Node.connect(:one@arch)
true
iex(one@arch)2> x = Node.spawn(:one@arch, Control, :controlling, [])
one@arch => controlling(0, 0, plays)
#PID<0.119.0>
iex(one@arch)3> send x, {:a_message}
got msg?
:a_message
{:a_message}
iex(one@arch)4>
The got msg? text is the output from the “controlling” function which is receiving messages - so that is working (as expected).
In module control I have this function definition
def setup(nodes, pids\\[])
def setup([], pids) do
pids
end
def setup([hd|tl], pids) do
case Node.connect(hd) do
true ->
IO.puts "Node.connect(#{hd}) is true"
pid = Node.spawn(hd, Connect, :controlling, [])
IO.puts "node #{hd} pid = #{inspect(pid)}"
setup(tl, [pid|pids])
false ->
IO.puts "node #{hd} no connect"
setup(tl, pids)
end
end
When I try to call this function, I get an error …
jon@arch:~/bridge$ iex --sname one -S mix
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:10] [hipe] [kernel-poll:false]
Compiling 1 file (.ex)
Interactive Elixir (1.6.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(one@arch)1> x = Control.setup([:one@arch])
Node.connect(one@arch) is true
node one@arch pid = #PID<0.127.0>
[#PID<0.127.0>]
iex(one@arch)2>
18:14:09.649 [error] Error in process #PID<0.127.0> on node :one@arch with exit value:
{:undef, [{Connect, :controlling, [], []}]}
I’m stuck … I don’t know what this error means, or why it works from the repl, but not from a function when it seems it’s doing the same thing.
Jonathan.