O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required