Ladies/Gents,Lets say I start up a process with Genserver behavior and make two callbacks handle_call(:stop, state) and terminate(reason, state). The handle_call callback simply does {:stop, :normal, reply, state} and the terminate just does and IO.puts("foo") and returns :ok.I have two questions.1. When I do GenServer.call(pid_of_process, :stop) the terminate actually gets called and outputs foo. However when I do Process.exit(pid_of_process, :normal) terminate does not get called. Is Process.exit a hard kill and the callback doesn't happen?
2. What is the best practice for shutting down a GenServer process?
--Thanks,Adam
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/003bf54a-1253-4966-b92e-46f71676e996%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
When trapping exits a non-kill exit signal will be turned into the message {:EXIT, from_pid, reason} with its ordering in the message queue as if it was a normal message. OTP processes, such as GenServer, will handle this exit message if it is from their parent process and terminate gracefully, i.e. call terminate/2 and exit.Process.exit(pid, :normal) is an antipattern and should probably never be used. A :normal exit signal does not propagate so the target pid will not be effected unless it is trapping exits. Process.exit(pid, :shutdown) is the usual choice but the exit signal will propagate to linked processes.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/77c9c10c-2076-4de2-9048-b1977b0d49f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.