Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. -module(named_process_basic).
  2. -compile([export_all]).
  3.  
  4. judge2(Band, Album) ->
  5. critic ! {self(), {Band, Album}},
  6. Pid = erlang:whereis(critic),
  7. receive
  8. {Pid, Criticism} -> Criticism
  9. after 2000 ->
  10. timeout
  11. end.
  12.  
  13. start_restarter() ->
  14. erlang:spawn(?MODULE, restarter, []).
  15.  
  16. restarter() ->
  17. erlang:process_flag(trap_exit, true),
  18. Pid = erlang:spawn_link(?MODULE, critic, []),
  19. register(critic, Pid),
  20. receive
  21. {'EXIT', Pid, normal} ->
  22. ok;
  23. {'EXIT', Pid, shutdown} -> % For manually stop the process
  24. ok;
  25. {'EXIT', Pid, _} ->
  26. restarter()
  27. end.
  28.  
  29. critic() ->
  30. receive
  31. {From, {"Rage Against the Turing Machine", "Unit Testify"}} ->
  32. From ! {self(), "They are great!"};
  33. {From, {"System of a Downtime", "Memoize"}} ->
  34. From ! {self(), "They're not Johnny Crash but they're good."};
  35. {From, {"Johnny Crash", "The Token Ring of Fire"}} ->
  36. From ! {self(), "Simply incredible."};
  37. {From, {_Band, _Album}} ->
  38. From ! {self(), "They are terrible!"}
  39. end,
  40. critic().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement