The behavior of the script is correct. You just skipped how the iex shell "helps you."
What do you do in your code, start the process connected , and not reset it. And since it is a related process, when it goes down, it is intended to bring down all related processes. There may be some “exceptions,” but what happens to your escript process.
Both shell managers and prcess can handle the message "I'm dead, so you should." They do this by changing the processing method (a related process, not a dying one) processes such messages. It allows them to receive them as regular messages (which you could receive in receive
if you want), rather than special, internal ones. To change this bahaviour, they use Process.flag( :trap_exit, :true)
( elixir doc , pointing to eralng one ). This allows the shell to simply print the death of killed processes, rather than dying every time you do something bad.
So you could do the same. Change this flag, and if you do not agree with the pattern in receive
on such messages. But I do not think what you are looking for. Since your process is singleton, and the supervisor does all the restarts, you really have no reason to refer to it in the first place. There is no need for death updates and re-launches, just let the manager worry about it. This is exactly the same as Joe Armstrong said (maybe to rephrase)
You do not need to know how to fix a vending machine in order to use it.
So simple, start
, not start_link
.
However, you might consider creating a connection with a supervisor who might also die after too many restarts (he may have been ordered to behave this way). And that allows you to take it (and a controlled process) when you die. Or it may be associated with your manager, application manager, or in some other way. It depends on your domain, and there is no bad decision, you just need to check what works with you. This is a design decision, and you either need to experiment or learn more about it:
http://elixir-lang.org/getting_started/mix_otp/5.html
http://www.erlang.org/doc/design_principles/des_princ.html
http://learnyousomeerlang.com/supervisors