Created
April 18, 2017 20:24
-
-
Save antoine/dd5934c601ffbc6ab5a27fa3551eb0a4 to your computer and use it in GitHub Desktop.
ex18
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
-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