Start and Stop Child Processes

Understand the process of starting and stopping the child processes.

We want each new game to be supervised. That means that we need the GameSupervisor process to start them. As the GameSupervisor process starts new game processes, it will link to them and trap exits so it can receive ordinary messages if any game should crash.

Changes to the GameSupervisor module

Let’s start by adding a public start_game/1 function in the GameSupervisor module to the start games. Once we have the supervisor starting the processes, it will take care of the rest:

def start_game(name), do:
  Supervisor.start_child(__MODULE__, [name])

Get hands-on with 1200+ tech skills courses.