Created
July 22, 2013 17:59
-
-
Save fogus/6056045 to your computer and use it in GitHub Desktop.
The bit of code that finally made Erlang supervisors click for me. From "Learn You Some Erlang for Great Good"
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
critic() -> | |
receive | |
{From, {"Rage Against the Turing Machine", "Unit Testify"}} -> | |
From ! {self(), "They are great!"}; | |
{From, {"System of a Downtime", "Memoize"}} -> | |
From ! {self(), "They're not Johnny Crash but they're good."}; | |
{From, {"Johnny Crash", "The Token Ring of Fire"}} -> | |
From ! {self(), "Simply incredible."}; | |
{From, {_Band, _Album}} -> | |
From ! {self(), "They are terrible!"} | |
end, | |
critic(). | |
start_critic2() -> | |
spawn(?MODULE, restarter, []). | |
restarter() -> | |
process_flag(trap_exit, true), | |
Pid= spawn_link(?MODULE, critic, []), | |
receive | |
{'EXIT', Pid, normal} -> % not a crash | |
ok; | |
{'EXIT', Pid, shutdown} -> % manual termination, not a crash | |
ok; | |
{'EXIT', Pid, _} -> | |
restarter() | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment