Skip to content

Instantly share code, notes, and snippets.

@hsavit1
Created July 28, 2016 16:33
Show Gist options
  • Save hsavit1/16d6399c22266af9fd0375c63169e365 to your computer and use it in GitHub Desktop.
Save hsavit1/16d6399c22266af9fd0375c63169e365 to your computer and use it in GitHub Desktop.
Small example of process messaging in elixir
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