January 2018
Intermediate to advanced
220 pages
5h 5m
English
Now that we have all the pieces assembled, let’s see how they all work together in IEx. We can start by aliasing the Game and GameSupervisor modules:
| | iex> alias IslandsEngine.{Game, GameSupervisor} |
| | [IslandsEngine.Game, IslandsEngine.GameSupervisor] |
Now we can use the GameSupervisor.start_game/1 function to start a new game:
| | iex> {:ok, game} = GameSupervisor.start_game("Hopper") |
| | {:ok, #PID<0.119.0>} |
Note that the PID is number 119. If we generate a via tuple for the first player’s name and check its PID with GenServer.whereis/1, it should be the same:
| | iex> via = Game.via_tuple("Hopper") |
| | {:via, Registry, {Registry.Game, "Hopper"}} |
| | |
| | iex> GenServer.whereis(via) ... |
Read now
Unlock full access