Skip to content

Instantly share code, notes, and snippets.

@bmitch
Created June 25, 2017 14:41
Show Gist options
  • Save bmitch/096dfc450ccc4e143c883c83e047cc8b to your computer and use it in GitHub Desktop.
Save bmitch/096dfc450ccc4e143c883c83e047cc8b to your computer and use it in GitHub Desktop.
simple_msg.exs
defmodule Spawn1 do
def greet do
receive do
{sender, msg} ->
send sender, { :ok, "Hello, #{msg}" }
greet
end
end
end
pid = spawn(Spawn1, :greet, [])
send pid, {self, "World!"}
receive do
{ :ok, message} ->
IO.puts message
end
send pid, {self, "Kermit!"}
receive do
{ :ok, message} ->
IO.puts message
after 500 ->
IO.puts "The greeter has gone away"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment