Guest User

Untitled

a guest
Feb 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. -module(countdown).
  2. -export([init/0, reload/0]).
  3. -export([tick/1]). % so we can spawn this properly.
  4.  
  5. %% spawn a countdown process with a default start time of 10 seconds.
  6. init() -> init(10).
  7. init(Time) ->
  8. register(ticker, spawn(?MODULE, tick, [Time])).
  9.  
  10. tick(Time) when Time >= 0 ->
  11. io:format("Tick ~p~n", [Time]),
  12. timer:sleep(999),
  13. receive reload ->
  14. ?MODULE:tick(Time - 1)
  15. after 1 -> tick(Time - 1)
  16. end;
  17. tick(_StartTime) ->
  18. io:format("Boom.~n", []),
  19. done.
  20.  
  21. reload() ->
  22. ticker ! reload.
Add Comment
Please, Sign In to add comment