summaryrefslogtreecommitdiffhomepage
path: root/elixir.html.markdown
diff options
context:
space:
mode:
authorJacob Ward <jacobward1898@gmail.com>2015-10-26 23:03:37 -0600
committerJacob Ward <jacobward1898@gmail.com>2015-10-26 23:03:37 -0600
commita0eb996415cc86cb72c44e793ebfacc3ec2d7b17 (patch)
tree516c83684b752f374758b9abd3b89be723478fd3 /elixir.html.markdown
parent66bc42e31bf62a1592f9b763e12c0b963b3e7d3d (diff)
parent44ca091c73afe13ec8760021cfed1d77afc5e4a5 (diff)
Merge remote-tracking branch 'adambard/master'
Diffstat (limited to 'elixir.html.markdown')
-rw-r--r--elixir.html.markdown9
1 files changed, 9 insertions, 0 deletions
diff --git a/elixir.html.markdown b/elixir.html.markdown
index c8599838..eedeb227 100644
--- a/elixir.html.markdown
+++ b/elixir.html.markdown
@@ -369,6 +369,13 @@ spawn(f) #=> #PID<0.40.0>
# messages to the process. To do message passing we use the `send` operator.
# For all of this to be useful we need to be able to receive messages. This is
# achieved with the `receive` mechanism:
+
+# The `receive do` block is used to listen for messages and process
+# them when they are received. A `receive do` block will only
+# process one received message. In order to process multiple
+# messages, a function with a `receive do` block must recursively
+# call itself to get into the `receive do` block again.
+
defmodule Geometry do
def area_loop do
receive do
@@ -384,6 +391,8 @@ end
# Compile the module and create a process that evaluates `area_loop` in the shell
pid = spawn(fn -> Geometry.area_loop() end) #=> #PID<0.40.0>
+# Alternatively
+pid = spawn(Geometry, :area_loop, [])
# Send a message to `pid` that will match a pattern in the receive statement
send pid, {:rectangle, 2, 3}