Skip to content

Instantly share code, notes, and snippets.

@Joakineee
Created July 6, 2020 15:28
Show Gist options
  • Save Joakineee/ca8dbbab845a662bf6c67a3456fa164e to your computer and use it in GitHub Desktop.
Save Joakineee/ca8dbbab845a662bf6c67a3456fa164e to your computer and use it in GitHub Desktop.
testing the mailbox
-module(mailbox).
-export([start/0,proccess/0,proccess2/0]).
start() ->
spawn(mailbox,proccess,[]).
proccess() ->
timer:sleep(3000),
receive
stop -> ok;
X -> io:format("message:~w~n",[{ok,X}]),
proccess()
end.
proccess2() ->
timer:sleep(3000),
receive
X -> case X of
stop -> ok;
_ -> io:format("message:~w~n",[{ok,X}]),
proccess2()
end
end.
%Erlang/OTP 22 [erts-10.4] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
%
%Eshell V10.4 (abort with ^G)
%1> PID2 = mailbox:start().
%<0.81.0>
%2> PID2 ! 1.
%message:{ok,1}
%1
%3> PID2 ! 2.
%2
%4> PID2 ! 3.
%3
%5> PID2 ! 4.
%4
%6> PID2 ! 5.
%5
%7> PID2 ! stop.
%stop
%8> PID2 ! 6.
%6
%9> PID2 ! 7.
%7
%10> PID2 ! 8.
%8
%message:{ok,2}
%message:{ok,3}
%message:{ok,4}
%message:{ok,5}
%11> PID2 ! 9.
%9
%12>
%12>
%12>
%12>
%12> PID3 = spawn(mailbox,proccess2,[]).
%<0.93.0>
%13> PID3 ! 1.
%message:{ok,1}
%1
%14> PID3 ! 2.
%2
%15> PID3 ! 3.
%3
%16> PID3 ! 4.
%4
%17> PID3 ! 5.
%5
%18> PID3 ! stop.
%stop
%19> PID3 ! 6.
%6
%20> PID3 ! 7.
%7
%21> PID3 ! 8.
%8
%22> PID3 ! 9.
%9
%23>
%message:{ok,2}
%message:{ok,3}
%message:{ok,4}
%message:{ok,5}
%23>
%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment