Skip to content

Instantly share code, notes, and snippets.

@michaeldperez
Created August 16, 2017 03:12
Show Gist options
  • Save michaeldperez/d24e5469c1f1bc28ed4ca811ea3d8016 to your computer and use it in GitHub Desktop.
Save michaeldperez/d24e5469c1f1bc28ed4ca811ea3d8016 to your computer and use it in GitHub Desktop.
Illustration of how Erlang's mailbox works.
-module(mailbox).
-export([receiver/0, receiver_ordered/0]).
receiver() ->
receive
stop -> io:format("Stopped.~n");
Msg -> io:format("Message received: ~s~n", [Msg]),
receiver()
end.
receiver_ordered() ->
receive
{first, FirstString} ->
io:format("First Message: ~s~n.", [FirstString])
end,
receive
{second, SecondString} ->
io:format("Second Message: ~s~n.", [SecondString]),
receiver_ordered()
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment