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>
Sourcepub fn set_state(&self, next: AsyncState<T, L>)
pub fn set_state(&self, next: AsyncState<T, L>)
Overrides the slot’s state directly.
Bypasses the future machinery. Exists so the
integration tests in core/tests/use_async/ can
exercise the match arms produced by users without
needing a live browser to run the future.
§Arguments
AsyncState<T, L>- AAsyncState<T, L>parameter.
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.
§Arguments
F: FnOnce() -> Fut + 'static- A generic type parameter.
Source§impl<T, L> UseAsyncHandle<T, L>
impl<T, L> UseAsyncHandle<T, L>
pub fn get_inner(&self) -> &usize
pub fn get_mut_inner(&mut self) -> &mut usize
pub fn set_inner(&mut self, val: usize) -> &mut Self
pub fn get__marker(&self) -> &PhantomData<fn() -> (T, L)>
pub fn get_mut__marker(&mut self) -> &mut PhantomData<fn() -> (T, L)>
pub fn set__marker(&mut self, val: PhantomData<fn() -> (T, L)>) -> &mut Self
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 moreimpl<T, L> Copy for UseAsyncHandle<T, L>
Source§impl<T, L> Debug for UseAsyncHandle<T, L>
impl<T, L> Debug for UseAsyncHandle<T, L>
Source§impl<T, L> Default for UseAsyncHandle<T, L>
impl<T, L> Default for UseAsyncHandle<T, L>
Source§fn default() -> Self
fn default() -> Self
Constructs a default UseAsyncHandle value.