GenServer Callbacks: terminate
Explore how the GenServer terminate/2 callback works to manage process shutdown in Elixir. Learn when it is invoked, limitations with external exits, and ways to ensure cleanup logic runs before a process stops.
The terminate callback function
The terminate/2 callback is usually invoked before the process exits, but only when the process itself is responsible for the exit. Most often, the exit results from explicitly returning {:stop, reason, state} from a callback (excluding init/1). It can also happen when an unhandled exception ...