I have a rebar3 app with a supervisor and some modules I want to execute a function before aborting the shell
I have tried adding an exit function in the supervisor,but its not working.I wanted to know if that's possible and if yes if I could have some examples that'd be great thank you.
I tried something like this but its not working
-module(shell_termination).
-export([start/0]).
start() ->
GracefulStopPid = spawn(fun graceful_stop/0),
process_flag(trap_exit,true),
register(gracefulStop, GracefulStopPid),
receive
shutdown ->
io:format("Application stopped gracefully~n"),
erlang:halt()
end.
graceful_stop() ->
process_flag(trap_exit,true),
io:format("Graceful stop process received shutdown signal~n"),
receive
shutdown ->
io:format("Graceful stop process received shutdown signal~n"),
exit(normal);
_->
io:format("Graceful stop process received shutdown signal~n")
end.
erlc shell_termination.erl
kaushik@kaushik-ThinkPad-E15-Gen-2:~/erlang$ erl
Erlang/OTP 26 [erts-14.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
Eshell V14.1 (press Ctrl+G to abort, type help(). for help)
1> shell_termination:graceful_stop().
<0.88.0>
2>
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
(l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
a