We use Live View with the following pattern to load some data asynchronously after the mount
and handle_params
are finished:
def mount(_, _, %Socket{} = socket) do
# does some initial loading
{:ok, socket}
end
def handle_params(_, _, %Socket{} = socket) do
# does some parameter specific loading
send(self(), :load_async_data)
{:noreply, socket}
end
def handle_info(:load_async_data, %Socket{} = socket) do
# loads some data asynchronously
{:noreply, socket}
end
We find that if you navigate to another page while handle_info
is running that we observe these errors:
Postgrex.Protocol (#PID<0.5610.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.8282.1> exited
Has anybody ever observed this before? Is this pattern what folks usually do for loading data asynchronously after handle_params
?