Created
June 25, 2017 14:41
-
-
Save bmitch/096dfc450ccc4e143c883c83e047cc8b to your computer and use it in GitHub Desktop.
simple_msg.exs
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 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