Messages
The expression
| | pid <- expression |
sends the value of the expression to the process with the given pid. This value is queued in a per-process mailbox, and the sender continues to run.
When a process wants to retrieve a message from its mailbox, it calls receive. This takes a block containing one or more clauses. Each clause consists of a pattern and an expression. Elixir looks at each message in the process’s mailbox in turn. For each message, it tries to match it against the patterns in the receive block. Once a match is found, it runs the corresponding code. If no match is found, Elixir waits until a new message arrives in the mailbox, and tests it. (This process means that any particular execution of receive will only inspect ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access