Elixir
Links vs. Monitors
-
A monitored process (
Process.monitor(pid)) sends up a:DOWNmessage when the child process is done.:reasonis set to:normalif the process exited cleanly:reasonis set to the error instance otherwise.
-
A linked process (
start_link) sends up an:EXITmessage when the child process is done.- By default, Elixir handles this message internally:
- The message is swallowed if
:reasonis:normal - The error is re-thrown on the parent if
:reasonis an error instance (and both parent and child are terminated)
- The message is swallowed if
- If the parent calls
Process.flag(:trap_exit, true)to indicate that it wants to trap exits, the:EXITmessage is received like any other message, and the parent is not automatically terminated even if the:EXITrepresents an error.
- By default, Elixir handles this message internally: