Skip to content

Instantly share code, notes, and snippets.

@antoine
Created April 18, 2017 20:24
Show Gist options
  • Save antoine/dd5934c601ffbc6ab5a27fa3551eb0a4 to your computer and use it in GitHub Desktop.
Save antoine/dd5934c601ffbc6ab5a27fa3551eb0a4 to your computer and use it in GitHub Desktop.
ex18
-module(concurrent18).
-export([receiver/0, receiver_slow/0, receiver_in_order/0]).
receiver() ->
receive
stop -> io:format("stop", []);
X -> io:format("~p~n", [X]),
receiver()
end.
receiver_slow() ->
timer:sleep(2000),
receive
stop -> io:format("stop", []);
X -> io:format("~p~n", [X]),
receiver_slow()
end.
receiver_in_order() ->
receiver_step(first).
what_do_we_expect_after(first)->
second;
what_do_we_expect_after(second)->
nothing.
receiver_step(nothing) ->
ok;
receiver_step(Step) ->
receive
{Step, FirstString}-> io:format("~p~n", [FirstString]),
receiver_step(what_do_we_expect_after(Step))
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment