Created
June 24, 2020 22:43
-
-
Save tecnowilliam/89478d508df80a6191dfecc6fb08c960 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| % Compile: c(mailbox). | |
| -module(mailbox). | |
| -author("William Vargas"). | |
| -version("1.0"). | |
| -export([receiver/0, receiver_seq/0, tests/0]). | |
| receiver() -> | |
| timer:sleep(1000), | |
| receive | |
| stop -> | |
| io:format("Stopped"); | |
| X -> | |
| io:format("Message: ~w~n",[X]), | |
| receiver() | |
| end. | |
| receiver_seq() -> | |
| receive | |
| {first, X} -> io:format("Received first message: ~w~n",[X]) | |
| end, | |
| receive | |
| {second, Y} -> io:format("Received second message: ~w~n",[Y]) | |
| end. | |
| tests() -> | |
| Rs = spawn(mailbox, receiver_seq, []), | |
| Rs ! {first, 'FirstString'}, | |
| Rs ! {second, 'SecondString'}, | |
| R = spawn(mailbox, receiver, []), | |
| R ! {ok, self()}, | |
| R ! stop. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good code! One caveat:
'FirstString'is not a string, it's an atom ;)