Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. -module(c18).
  2.  
  3. -export([receiver/0,receiver2/0,receiver3/0,sequence/0]).
  4. -export([receiver_test/0,receiver2_test/0,receiver3_test/0,sequence_test/0]).
  5.  
  6. receiver() ->
  7. %timer:sleep(1000),
  8. receive
  9. X ->
  10. io:format("message: ~p~n", [X])
  11. end,
  12. receiver().
  13.  
  14. receiver2() ->
  15. %timer:sleep(1000),
  16. receive
  17. X ->
  18. io:format("message: ~p~n", [X]),
  19. case X of
  20. quit -> ok;
  21. _ -> receiver2()
  22. end
  23. end.
  24.  
  25. receiver3() ->
  26. %timer:sleep(1000),
  27. receive
  28. quit ->
  29. io:format("message: ~p~n", [quit]);
  30. X ->
  31. io:format("message: ~p~n", [X]),
  32. receiver3()
  33. end.
  34.  
  35. sequence() ->
  36. receive
  37. {first, FirstString} -> io:format("message: ~p~n", [FirstString])
  38. end,
  39. receive
  40. {second, SecondString} -> io:format("message: ~p~n", [SecondString])
  41. end.
  42.  
  43. receiver_test() ->
  44. Pid = spawn(?MODULE, receiver, []),
  45. Pid ! "Message 1",
  46. Pid ! "Message 2",
  47. Pid ! "Message 3".
  48.  
  49. receiver2_test() ->
  50. Pid = spawn(?MODULE, receiver2, []),
  51. Pid ! "Message 1",
  52. Pid ! "Message 2",
  53. Pid ! "Message 3",
  54. Pid ! stop.
  55.  
  56. receiver3_test() ->
  57. Pid = spawn(?MODULE, receiver3, []),
  58. Pid ! "Message 1",
  59. Pid ! "Message 2",
  60. Pid ! "Message 3",
  61. Pid ! stop.
  62.  
  63. sequence_test() ->
  64. Pid = spawn(?MODULE, sequence, []),
  65. Pid ! {second, "World"},
  66. Pid ! {first, "Hello"}.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement