Sending messages between processes
In Elixir, communication between processes is performed via message passing. Each process has a mailbox where messages from the "outside" world are placed, waiting to be processed. Once that happens, if a response is required, another message will be sent, and another mailbox will get a message!
Getting ready
To get started, go to the code repository where the messages.ex
file is located and open a new IEx terminal session. The IEx terminal session will also be an actor in this recipe! We will send messages from it to the process containing the code defined in the module.
How to do it…
Follow these steps to send messages between processes:
- Once our session is started, load and compile the
messages.ex
module:iex(1)> c "messages.ex" [Messages]
- Next, spawn a new process containing the code from our module:
iex(2)> {:ok, pid} = Messages.start_link {:ok, #PID<0.61.0>}
- To make things easier, we will register our newly spawned...