AI Features

Initialize the GenServer State

Learn how to initialize the GenServer state.

We'll cover the following...

GenServer in the game.ex module

Until now, we’ve relied directly on the built-in start_link/3 function from GenServer to start new processes. However, we can do better.

When we run GenServer.start_link(Game, <initial state>), the idea that we’re starting a new game process is buried in the arguments. It would be much clearer if we could bring the Game module out front by writing Game.start_link(<initial state>).

To do this, we follow the GenServer pattern and define a public function that wraps a GenServer module ...