diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2024-02-23 07:08:18 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2024-02-23 07:08:18 +0100 |
commit | 5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e (patch) | |
tree | 982ca2e7f9ac4e8c350dfb5c4f60bcfdfff5afaf /learn-you-some-erlang/band_supervisor.erl | |
parent | 05ae56e5e89abf2993f84e6d52b250131f247c35 (diff) | |
download | erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.gz erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.bz2 erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.xz erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.zip |
wip
Diffstat (limited to 'learn-you-some-erlang/band_supervisor.erl')
-rw-r--r-- | learn-you-some-erlang/band_supervisor.erl | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/learn-you-some-erlang/band_supervisor.erl b/learn-you-some-erlang/band_supervisor.erl new file mode 100644 index 0000000..dd17ba8 --- /dev/null +++ b/learn-you-some-erlang/band_supervisor.erl @@ -0,0 +1,41 @@ +-module(band_supervisor). +-behaviour(supervisor). + +-export([start_link/1]). +-export([init/1]). + +start_link(Type) -> + supervisor:start_link({local,?MODULE}, ?MODULE, Type). + +%% The band supervisor will allow its band members to make a few +%% mistakes before shutting down all operations, based on what +%% mood he's in. A lenient supervisor will tolerate more mistakes +%% than an angry supervisor, who'll tolerate more than a +%% complete jerk supervisor +init(lenient) -> + init({one_for_one, 3, 60}); +init(angry) -> + init({rest_for_one, 2, 60}); +init(jerk) -> + init({one_for_all, 1, 60}); +init(jamband) -> + {ok, {{simple_one_for_one, 3, 60}, + [{jam_musician, + {musicians, start_link, []}, + temporary, 1000, worker, [musicians]} + ]}}; +init({RestartStrategy, MaxRestart, MaxTime}) -> + {ok, {{RestartStrategy, MaxRestart, MaxTime}, + [{singer, + {musicians, start_link, [singer, good]}, + permanent, 1000, worker, [musicians]}, + {bass, + {musicians, start_link, [bass, good]}, + temporary, 1000, worker, [musicians]}, + {drum, + {musicians, start_link, [drum, bad]}, + transient, 1000, worker, [musicians]}, + {keytar, + {musicians, start_link, [keytar, good]}, + transient, 1000, worker, [musicians]} + ]}}. |