Module:terminate(Reason, State)
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.
Even if the gen_server is not part of a supervision tree, this function will be called if it receives an 'EXIT' message from its parent. Reason will be the same as in the 'EXIT' message.
Otherwise, the gen_server will be immediately terminated.
Если gen_server не является частью дерева супервизора, то он все равно получит 'EXIT' от предка.
В gen_server.erl есть такое место:
decode_msg(Msg, Parent, Name, State, Mod, Time, Debug, Hib) ->
case Msg of
...
{'EXIT', Parent, Reason} ->
terminate(Reason, Name, Msg, Mod, State, Debug);
...
Но видимо это произойдет только если будет существовать link с предком, а сам gen_server будет делать trap exit. То есть, я не понимаю, чем это будет отличаться от случая с супервизором. Как-то в документации расплывчато написано.
среда, 5 июня 2013 г., 23:01:56 UTC+4 пользователь DarkIT написал: