summaryrefslogtreecommitdiffhomepage
path: root/elixir.html.markdown
diff options
context:
space:
mode:
authorAayush Ranaut <aayush.ranaut@gmail.com>2015-12-05 11:10:16 +0530
committerAayush Ranaut <aayush.ranaut@gmail.com>2015-12-05 11:10:16 +0530
commitdc675a47edaeced79e13bf99d120c195a38b9ecf (patch)
treee626142c07fa41695b959b606d4337929c9669ed /elixir.html.markdown
parent0049a475edba88f6537b2490ca9506df23b46368 (diff)
parentc8475eacd742a1c8c6340121aa95f32f65421113 (diff)
Merged and removed confusing comments in python
Diffstat (limited to 'elixir.html.markdown')
-rw-r--r--elixir.html.markdown11
1 files changed, 11 insertions, 0 deletions
diff --git a/elixir.html.markdown b/elixir.html.markdown
index c8599838..720e080c 100644
--- a/elixir.html.markdown
+++ b/elixir.html.markdown
@@ -343,6 +343,7 @@ rescue
RuntimeError -> "rescued a runtime error"
_error -> "this will rescue any error"
end
+#=> "rescued a runtime error"
# All exceptions have a message
try do
@@ -351,6 +352,7 @@ rescue
x in [RuntimeError] ->
x.message
end
+#=> "some error"
## ---------------------------
## -- Concurrency
@@ -369,6 +371,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 +393,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}