[erlang-questions] Question about behaviours in Erlang/OTP
ANTHONY MOLINARO
anthonym@REDACTED
Tue Jul 15 01:20:41 CEST 2014
Hi Yves,
In the gen_server manual, in the Module:terminate/2 it states
If the gen_server is part of a supervision tree and is ordered by its supervisor to terminate, this function will be called with Reason=shutdown if the following conditions apply:
* the gen_server has been set to trap exit signals, and
* the shutdown strategy as defined in the supervisor’s child specification is an integer timeout value, not brutal_kill
So, if want to ensure that your gen_server terminate/2 function is call you need to trap exits. This is most common if there is some amount of cleanup you want to make sure happens before the gen_server terminates.
HTH,
-Anthony
On Jul 13, 2014, at 4:59 PM, Yves S. Garret <yoursurrogategod@REDACTED> wrote:
> Hello,
>
> I'm looking at some code that was written where a user uses a behaviour of gen_server and then uses a process_flag(trap_exit, true). To me, this seems like a supervisor behaviour would work better.
>
> What would be a better approach in this case? To declare this module a supervisor? Is it possible (sensible? logical?) to give the same module gen_server and supervisor behaviours?
>
> Thanks in advance!
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list