-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproc.erl
36 lines (32 loc) · 877 Bytes
/
proc.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-module(proc).
-export([start/0, proce/0, proce2/2]).
proce() ->
receive
{start, Messages, Pid2} ->
io:format("Starting~n"),
[H, M] = Messages,
Pid2 ! {message, H, self()},
Pid2 ! {message, M, self()};
{message, Message, OtherPid} ->
io:format("Enter message: " ++ Message ++ " replying ~n"),
OtherPid ! {reply, Message ++ " Received~n"};
{finished} ->
ok
end,
proce().
proce2([], Pid) ->
Pid ! {finished},
ok;
proce2(Messages, Pid) ->
[Curr|Rem] = Messages,
Pid ! {message, Curr, self()},
receive
{reply, Message} ->
io:format("Received reply: " ++ Message)
end,
proce2(Rem, Pid),
ok.
start() ->
Pid1 = spawn(?MODULE, proce, []),
spawn(?MODULE, proce2, [["Hello", "Hello2"], Pid1]),
ok.