Skip to content

Instantly share code, notes, and snippets.

@leikind
Created December 30, 2011 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leikind/1541608 to your computer and use it in GitHub Desktop.
Save leikind/1541608 to your computer and use it in GitHub Desktop.
-module(simple_exit_demo).
-export([simple_exit_demo/0]).
simple_exit_demo() ->
spawn(fun() -> start_processes() end).
start_processes() ->
process_flag(trap_exit, true),
spawn_link(fun() -> timer:sleep(1000) end),
spawn_link(fun() -> timer:sleep(2000), exit(exiting_for_a_reason) end),
spawn_link(fun() -> timer:sleep(3000), exit(normal) end),
spawn_link(fun() -> timer:sleep(4000), 1 / 0 end),
spawn_link(fun() -> timer:sleep(5000), erlang:error(raising_error) end),
spawn_link(fun() -> timer:sleep(6000), throw(throwing_error) end),
listen_to_exits().
listen_to_exits() ->
receive
Message -> io:format("Caught a system message: ~p~n~n", [Message]),
listen_to_exits()
after 7000 ->
io:format("Show's over~n")
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment