From 5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 23 Feb 2024 07:08:18 +0100 Subject: wip --- learn-you-some-erlang/band_supervisor.erl | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 learn-you-some-erlang/band_supervisor.erl (limited to 'learn-you-some-erlang/band_supervisor.erl') 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]} + ]}}. -- cgit v1.2.3