OTP Supervisors Manage GenServer Lifecycles

Let’s create a new project, one with a supervisor. We’ll call this app super_duper:

 [otp] ➔ mix new super_duper --sup
 ...
 * creating lib/super_duper/application.ex
 ...
 
 [otp] ➔ cd super_duper/

Notice the list of files mix created for you. One of them is application.ex. That’s your supervisor.

Application is a Supervisor Template

Just as the GenServer module is a template for a generic server, the Application module is a template for a supervisor. The documentation says, “Applications are the idiomatic way to package software in Erlang/OTP.” When you start an application, you’re really starting a supervisor, and that supervisor is starting the GenServers that make up the rest of your code base. ...

Get Programmer Passport: OTP 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.