Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(countdown).
- -export([init/0, reload/0]).
- -export([tick/1]). % so we can spawn this properly.
- %% spawn a countdown process with a default start time of 10 seconds.
- init() -> init(10).
- init(Time) ->
- register(ticker, spawn(?MODULE, tick, [Time])).
- tick(Time) when Time >= 0 ->
- io:format("Tick ~p~n", [Time]),
- timer:sleep(999),
- receive reload ->
- ?MODULE:tick(Time - 1)
- after 1 -> tick(Time - 1)
- end;
- tick(_StartTime) ->
- io:format("Boom.~n", []),
- done.
- reload() ->
- ticker ! reload.
Add Comment
Please, Sign In to add comment