Supervisors and Workers

An Elixir supervisor has just one purpose—it manages one or more processes. (As we’ll discuss later, these processes can be workers or other supervisors.)

At its simplest, a supervisor is a process that uses the OTP supervisor behavior. It is given a list of processes to monitor and is told what to do if a process dies, and how to prevent restart loops (when a process is restarted, dies, gets restarted, dies, and so on).

To do this, the supervisor uses the Erlang VM’s process-linking and -monitoring facilities. We talked about these when we covered spawn.

You can write supervisors as separate modules, but the Elixir style is to include them inline. The easiest way to get started is to create your project with the ...

Get Programming Elixir ≥ 1.6 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.