aboutsummaryrefslogtreecommitdiff
path: root/learn-you-some-erlang/reminder/src/sup.erl
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2024-02-23 07:08:18 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2024-02-23 07:08:18 +0100
commit5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e (patch)
tree982ca2e7f9ac4e8c350dfb5c4f60bcfdfff5afaf /learn-you-some-erlang/reminder/src/sup.erl
parent05ae56e5e89abf2993f84e6d52b250131f247c35 (diff)
downloaderlang-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/reminder/src/sup.erl')
-rw-r--r--learn-you-some-erlang/reminder/src/sup.erl22
1 files changed, 22 insertions, 0 deletions
diff --git a/learn-you-some-erlang/reminder/src/sup.erl b/learn-you-some-erlang/reminder/src/sup.erl
new file mode 100644
index 0000000..71a463b
--- /dev/null
+++ b/learn-you-some-erlang/reminder/src/sup.erl
@@ -0,0 +1,22 @@
+-module(sup).
+-export([start/2, start_link/2, init/1, loop/1]).
+
+start(Mod, Args) ->
+ spawn(?MODULE, init, [{Mod, Args}]).
+
+start_link(Mod,Args) ->
+ spawn_link(?MODULE, init, [{Mod, Args}]).
+
+init({Mod,Args}) ->
+ process_flag(trap_exit, true),
+ loop({Mod,start_link,Args}).
+
+loop({M,F,A}) ->
+ Pid = apply(M,F,A),
+ receive
+ {'EXIT', _From, shutdown} ->
+ exit(shutdown); % will kill the child too
+ {'EXIT', Pid, Reason} ->
+ io:format("Process ~p exited for reason ~p~n",[Pid,Reason]),
+ loop({M,F,A})
+ end.