Skip to content

Instantly share code, notes, and snippets.

@robstewart57
Created August 6, 2013 17:31
Show Gist options
  • Save robstewart57/6166636 to your computer and use it in GitHub Desktop.
Save robstewart57/6166636 to your computer and use it in GitHub Desktop.
-module(ammunition_factory).
-export([repeat_explosion/2,time_bomb/1]).
time_bomb(0) -> exit("boom!");
time_bomb(N) ->
timer:sleep(1000),
time_bomb(N-1).
repeat_explosion(0,N) ->
_Pid = spawn_monitor(fun() -> time_bomb(N) end),
receive X -> io:format("~p\n",[X])
end;
repeat_explosion(R,N) ->
_Pid = spawn_monitor(fun() -> time_bomb(N) end),
receive X -> io:format("~p\n",[X]), repeat_explosion(R-1,N)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment