I have a mix project with as simple as possible a Supervisor and GenServer. When I call from iex:
EchoCmd.Supervisor.start_link([:Hello])
GenServer.call(:echoserver, :echo)
GenServer.call(:echoserver, :mumble)
GenServer.call(:echoserver, :echo)
The :mumble call raises an exception, then the GenServer is restarted and the second :echo call works ok.
If I run the code in any other way the Supervisor fails to restart the GenServer. For example, I create an escript of the project with the main module as follows:
defmodule EchoCmd.Echo do
def main(args) do
EchoCmd.Supervisor.start_link([:Hello])
GenServer.call(:echoserver, :echo)
GenServer.call(:echoserver, :mumble)
GenServer.call(:echoserver, :echo)
end
end
The :mumble call raises an exception and the escript terminates without the Supervisor restarting the GenServer.
I've not included the Supervisor and Server modules code because they work fine when called from iex, so I'm guessing they're not needed here.
Do I have a conceptual misunderstanding? Is this not possible, or am I doing something wrong?