pub struct UseAsyncHandle<T, L = ()>{ /* private fields */ }Expand description
use_async’s reactive handle, stored in the hook context slot and
returned to the user on each render.
The handle exposes three fields:
state: the currentAsyncState<T, L>(matches what the user shouldmatchon inhtml!).refetch: triggers the future to run again, regardless of whether the previous attempt completed or is still in flight.cancel: drops the in-flight future (if any) and prevents itsOk/Errbranches from mutating the state. Subsequent renders will still call the future again on the next mount.
Cloning a handle is cheap — UseAsyncHandle is Copy if its
generic parameters are. Use it from event handlers the same way
you’d use a Signal<T>.
Implementations§
Source§impl<T, L> UseAsyncHandle<T, L>
impl<T, L> UseAsyncHandle<T, L>
Sourcepub fn state(&self) -> AsyncState<T, L>
pub fn state(&self) -> AsyncState<T, L>
Returns the current reactive state.
Sourcepub fn refetch<F, Fut, E>(&self, factory: F)
pub fn refetch<F, Fut, E>(&self, factory: F)
Re-runs the future, ignoring any in-flight result from a previous attempt.
Internally this sets a fresh cancel flag, transitions the
state to Loading(L::empty()), and spawns the future. The
existing in-flight future will see its cancel flag flipped
and exit early.
The error type E is intentionally a free type parameter
(rather than String or a dedicated AsyncError trait) so
Result<T, JsValue>, Result<T, MyDomainError>, and
Result<T, String> all work without an adapter layer.
Trait Implementations§
Source§impl<T, L> Clone for UseAsyncHandle<T, L>
impl<T, L> Clone for UseAsyncHandle<T, L>
Source§fn clone(&self) -> UseAsyncHandle<T, L>
fn clone(&self) -> UseAsyncHandle<T, L>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more