The terminate function is called for clean up. Be cautious because it seems terminate is not always executed.
defmodule Transactions do
use GenServer, restart: :transient, shutdown: 10_000
alias Transactions.Current
# Take state from stach, or empty state
def start_link(state \\ %{}) do
GenServer.start_link(__MODULE__, state, name: __MODULE__)
end
...
def terminate(reason, state) do
# Save state to stash
end
...
end
There is a stash example in this presentation
around 19:30…


















