Writing a few small experiments to familiarise myself with the language, but have run into an issue which I'm guessing is elementary.
I have a simple supervisor, with 3 simple workers:
def init do
Supervisor.start_link(
[
worker(__MODULE__, [:"process-1"], [function: :test, id: :"p-1"]),
worker(__MODULE__, [:"process-2"], [function: :test, id: :"p-2"]),
worker(__MODULE__, [:"process-3"], [function: :test, id: :"p-3"])
],
strategy: :one_for_one
)
end
":test" looks like this:
def test(name) do
flag(:trap_exit, true)
IO.puts "Testing: #{name} == #{inspect self}"
register(self, name)
receive do
{ :death } ->
IO.puts("I WOZ MURDERED!")
exit(self, "Ex process...")
{ :life } ->
IO.puts("#{inspect self} is listening...")
__MODULE__.test(name)
{ :EXIT, pid, reason } ->
IO.puts "REASON: #{inspect reason} - PROCESS: #{inspect pid}"
end
end
This compiles, but it only ever spawns one process, and hangs/blocks iex.
In contrast, when I use a simple chain of 'spawn_link'ed' processes, all three (or however many) processes start concurrently and return control to the iex shell so I can send the registered processes messages from the command line.
My intention, for now, is to create an OTP supervisor, run and register three (or however many) workers processes and attach them to the supervisor, send a simple message to kill a given worker, and then have the supervisor restart it.
What am I doing wrong?