Passing Messages
Learn how to initialize GenServers with the correct state.
We'll cover the following...
The simplest thing we can do with a GenServer
is spawn a new server process and send it a message. We’ve just learned to spawn a new game server process and bind the resulting PID to a variable. Once we have that PID, we can use Kernel.send/2
to send it a message. Once we have the message passing down, we can customize behavior based on that message.
New IEx session
Let’s see how this all works.
In a new IEx session, let’s start a new game process and send it the :first
message:
alias IslandsEngine.Game
{:ok, game} =
...