Search⌘ K
AI Features

Build a Supervisor for the Game

Explore how to create a custom GameSupervisor module in Elixir using the Supervisor behavior. Learn to start and manage dynamic game processes with the :simple_one_for_one strategy. Understand how to implement supervisor initialization and control functions for reliable process supervision and recovery.

Starting with a custom supervisor

Now that we have the Game module’s child specification showing the values we want, we’re ready to create a custom supervisor. We explore two ways to do this. One is as simple as starting a supervisor process with the right options. The other involves creating a new module that contains the callbacks we need and also some helper functions we want.

Each game in the Islands is a separate GenServer process. These processes come and go as players start new games and then end them. We need a supervisor specifically to monitor games, and the :simple_one_for_one strategy is perfect for processes we need to start and stop at runtime.

Most of the work of creating a custom supervisor happens when starting a new supervisor process with the right options. After that, the supervisor process itself does the rest. There are two ways to do this. ...