Using monitors

In certain scenarios, it is better to have errors being propagated in a single direction. This is the use case for monitors. A monitor is similar to a link, but while the latter is always bidirectional, the former is always unidirectional. Moreover, a process linked to others may terminate when one of them terminates (unless it's trapping exits), whereas monitors never cause the termination of the process that's monitoring others, and the default behavior is that it always receives a message in its mailbox. A single process may create multiple monitors.

To monitor a process, you call the Process.monitor/1 function, providing as an argument the PID of the process you want to monitor. You may also provide the alias of a registered ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.