I have a general LiveView component which starts a process in the underlying system and waits for a confirmation to indicate it has been started successfully.
defmodule MyComponent do
...
def confirm_on(id) do
send_update(__MODULE__, id: id, status: :on)
end
def update(%{status: status}, socket) do
{:ok, assign(socket,
state: %State{socket.assigns.state |
status: status})}
end
end
What happens is that, depending on where the confirm_on()
is called, the update is caught or not.
Works:
def start_system() do
start_some_lengthy_process()
MyComponent.confirm_on(:live_id)
end
Doesn’t Work:
def start_system() do
spawn_link(fn ->
start_some_lengthy_process()
MyComponent.confirm_on(:live_id)
end)
end
What does it mean it doesn’t work?
In both cases, MyComponent.confirm_on()
is indeed called and an update is emitted
{:phoenix, :send_update, {MyComponent, %{:live_id, status: :on}}}
However, only in the first case, this update is caught in the update
function, in the second case it fails somewhere silently.
Is there a ways to track the progress of the emitted LiveView
update?