Skip to content

Instantly share code, notes, and snippets.

@fogus
Created July 22, 2013 17:59
Show Gist options
  • Save fogus/6056045 to your computer and use it in GitHub Desktop.
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"
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