-
Notifications
You must be signed in to change notification settings - Fork 0
/
exchange.erl
38 lines (29 loc) · 909 Bytes
/
exchange.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
37
38
-module(exchange).
-export([start/0, initiation/0, name/2]).
initiation() ->
TimeOut = 10000,
receive
{Callee,Caller, TimeStamp, Type}->
io:format("~p received ~p message from ~p [~p]~n", [Callee, Type, Caller,TimeStamp]),
initiation();
{Callee, Caller, TimeStamp} ->
io:format("~p received reply message from ~p [~p]~n", [Callee, Caller,TimeStamp]),
initiation()
after
TimeOut ->
io:format("~nProcess 'Master' has received no calls for 10 seconds, ending...")
end.
name(X,Map1)->
io:fwrite(X),
io:fwrite(" => "),
io:fwrite("~p~n",[maps:get(X,Map1)]).
start() ->
io:fwrite("\n\n\n"),
{ok, L} = file:consult("calls.txt"),
Map1 = maps:from_list(L),
Names = maps:keys(Map1),
io:fwrite("** Calls to be made **\n"),
lists:map(fun(X)-> name(X,Map1) end, Names),
io:fwrite("\n"),
calling:placeCall(self(), maps:keys(Map1), Map1),
initiation().