Created
December 30, 2011 21:44
-
-
Save leikind/1541608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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