Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(named_process_basic).
- -compile([export_all]).
- judge2(Band, Album) ->
- critic ! {self(), {Band, Album}},
- Pid = erlang:whereis(critic),
- receive
- {Pid, Criticism} -> Criticism
- after 2000 ->
- timeout
- end.
- start_restarter() ->
- erlang:spawn(?MODULE, restarter, []).
- restarter() ->
- erlang:process_flag(trap_exit, true),
- Pid = erlang:spawn_link(?MODULE, critic, []),
- register(critic, Pid),
- receive
- {'EXIT', Pid, normal} ->
- ok;
- {'EXIT', Pid, shutdown} -> % For manually stop the process
- ok;
- {'EXIT', Pid, _} ->
- restarter()
- end.
- critic() ->
- receive
- {From, {"Rage Against the Turing Machine", "Unit Testify"}} ->
- From ! {self(), "They are great!"};
- {From, {"System of a Downtime", "Memoize"}} ->
- From ! {self(), "They're not Johnny Crash but they're good."};
- {From, {"Johnny Crash", "The Token Ring of Fire"}} ->
- From ! {self(), "Simply incredible."};
- {From, {_Band, _Album}} ->
- From ! {self(), "They are terrible!"}
- end,
- critic().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement