Created
July 28, 2016 16:33
-
-
Save hsavit1/16d6399c22266af9fd0375c63169e365 to your computer and use it in GitHub Desktop.
Small example of process messaging in elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Speaker do | |
def speak do | |
receive do | |
{:say, msg} -> | |
IO.puts(msg) | |
speak | |
_other -> | |
speak # throw away the message | |
end | |
end | |
end | |
pid = spawn(Speaker, :speak, []) | |
send pid, {:say, "Hello, World!"} | |
# => prints "Hello, World!" to standard out | |
send pid, {:say, "Goodbye, World!"} | |
# => prints "Goodbye, World!" to standard out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment