O'Reilly logo

Functional Web Development with Elixir, OTP, and Phoenix by Lance Halvorsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Starting and Stopping 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, under the hood it will link to them and trap exits so that it can receive ordinary messages if any of the games should crash.

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

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

Here’s what happens when we call start_game/1:

  • __MODULE__ here evaluates to GameSupervisor, which is the local ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required