View Source Phoenix.LiveView.AsyncResult (Phoenix LiveView v0.20.0)

Provides a datastructure for tracking the state of an async assign.

See the Async Operations section of the Phoenix.LiveView docs for more information.

Fields

  • :ok? - When true, indicates the :result has been set successfully at least once.
  • :loading - The current loading state
  • :failed - The current failed state
  • :result - The successful result of the async task

Summary

Functions

Updates the failed state.

Updates the loading state.

Updates the successful result.

Functions

Updates the failed state.

When failed, the loading state will be reset to nil.

Examples

AsyncResult.failed(my_async, {:exit, :boom})
AsyncResult.failed(my_async, {:error, reason})

Updates the loading state.

When loading, the failed state will be reset to nil.

Examples

AsyncResult.loading()
AsyncResult.loading(my_async)
AsyncResult.loading(my_async, %{my: :loading_state})
Link to this function

loading(result, loading_state)

View Source

Updates the successful result.

The :ok? field will also be set to true to indicate this result has completed successfully at least once, regardless of future state changes.

When ok'd, the loading and failed state will be reset to nil.

Examples

AsyncResult.ok(my_async, my_result)