Runtime support for async :name do run fn assigns -> ... end end
declarations and the fire :name op.
fire/3 uses Phoenix.LiveView.start_async/3 to spawn the task,
which:
- tracks the task pid on the socket so
render_async/2in tests sees the in-flight work — crucial for parity with vanillaassign_async/start_async - routes the result through
handle_async/3(generated by the compile-time transformer; seehandle_lavash_async/3below) - cancels and restarts the task if
fireis called again while one is in flight
Decoupling rationale
The declaration (what the work IS) lives at the
async :name do ... end site. The trigger (WHEN it runs) lives
wherever fire :name is called — mount do, an action body, or
a message body. One declaration, multiple trigger paths, no
duplication.
Summary
Functions
Fire the named async task on the given socket. Looks up the
module's registered async definitions and starts the task via
Phoenix.LiveView.start_async/3. The field is set to
AsyncResult.loading() immediately.
Routes a handle_async/3 callback for a lavash-declared async
task. Called by the generated handle_async/3 clause when the
result name matches a registered async declaration.
Functions
Fire the named async task on the given socket. Looks up the
module's registered async definitions and starts the task via
Phoenix.LiveView.start_async/3. The field is set to
AsyncResult.loading() immediately.
Returns the updated socket.
Routes a handle_async/3 callback for a lavash-declared async
task. Called by the generated handle_async/3 clause when the
result name matches a registered async declaration.
Wraps the result in AsyncResult.ok/1 or AsyncResult.failed/2
to match vanilla assign_async shape, then runs through the
reactive recompute + project pipeline so downstream derived
fields see the new value.