Hi!
I have some doubts about this documentation:
https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:terminate/2
I was trying to catch when / why every exit reason is triggered to understand the possible situations where some socket is disconnected and make some decisions.
From what I’ve read on the documentation there are 5 possible exit statuses:
- :normal
- :shutdown
- {:shutdown, :left}
- {:shutdown, :closed}
- term()
I can’t figure out when :normal
or {:shutdown, :left}
will be called. Could the documentation be outdated? Probably I’m missing something.
These are some tests I did:
Notice: Just in case, I have trap exit enable on liveview server
Results:
| Action | Reason |
|-------------------------|----------------------|
| push_redirect | :shutdown |
|. redirect | :shutdown |
| kill lv process | :shutdown |
| close tab / browser | {:shutdown, :closed} |
| change URL | {:shutdown, :closed} |
| refresh | {:shutdown, :closed} |
|disconnect socket with JS| {:shutdown, :closed} |
| raise error | term() |
Method used to kill liveview process
Process.whereis(QtixWeb.Endpoint) |> Process.exit(:kill)
I’m not able to get {:shutdown, :left}
not :normal
I found this peace of code on liveview project:
def handle_info(%Message{topic: topic, event: "phx_leave"} = msg, %{topic: topic} = state) do
send(state.socket.transport_pid, {:socket_close, self(), {:shutdown, :left}})
reply(state, msg.ref, :ok, %{})
{:stop, {:shutdown, :left}, state}
end
So I think it is something related with the Phoenix.socket
, am I right?
On the other hand, I couldn’t find the way to get the :normal
reason neither.
Once I have this clear, how possible is it to improve the documentation explaining every case? Is there a standard for keeping the documentation so minimalist?
Thanks!