Working with an example

Let's build out some code to see how this works and build upon it a little bit more. We'll start by building our first little process shell:

process = fn ->  receive do    {:msg, greeting} -> IO.puts("I received: #{greeting}")  endend

Now, if you just copy and paste that into an IEx window and try to run it (through process.()), you'll end up getting a process that just kind of hangs forever; something like this:

iex(1)> process.()# ...a blank line followed by a whole lot of nothing

You'll end up having to interrupt it and kill the IEx session entirely. The reason for that is the line in there towards the top, the receive do ... end block. This will completely lock a process until it receives an actionable message. This ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.