Skip to content

Instantly share code, notes, and snippets.

@lukebakken
Last active April 6, 2017 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukebakken/6da9c8c1ce923c3873d0e5d115ddfffb to your computer and use it in GitHub Desktop.
Save lukebakken/6da9c8c1ce923c3873d0e5d115ddfffb to your computer and use it in GitHub Desktop.
Erlang Gotcha

What could go wrong here?

receiver() ->
    receive
        {first, Msg} ->
            io:format("receiver first ~s~n", [Msg]),
            receive
                {second, Msg} ->
                    io:format("receiver second ~s~n", [Msg]);
                stop ->
                    io:format("receiver inner STOP~n")
            end;
        stop ->
            io:format("receiver outer STOP~n")
    end,
    receiver().

Consider this input:

Pid ! {second, "ex3_1 second"},
Pid ! {first, "ex3_1 first"},
Pid ! stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment