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>
Inherent implementation of UseAsyncHandle — public reactive API.
impl<T, L> UseAsyncHandle<T, L>
Inherent implementation of UseAsyncHandle — public reactive API.
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.
factory is called immediately, on the calling thread, and
the future it returns is spawned. The handle’s state is not
touched on this path: the write-back to Ok / Err happens
inside the spawned task, so a caller that reads
Self::state straight after this call still sees the
previous result.
In the usual match on the state, refetch is called from the
Loading arm during render, so there is nothing to reset —
but a refetch issued from a settled Ok or Err (a refresh
button, say) leaves the stale value on screen until the future
resolves. Call Self::set_state with
AsyncState::Loading(L::empty()) first if that window matters.
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- 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>
impl<T, L> Copy for UseAsyncHandle<T, L>
Blanket Copy for any generic instance — both fields are
themselves Copy (usize, PhantomData<fn pointer>).
The where clause must be repeated because a separate impl
block cannot inherit bounds from the type declaration.
Source§impl<T, L> Debug for UseAsyncHandle<T, L>
Debug formatting for UseAsyncHandle.
impl<T, L> Debug for UseAsyncHandle<T, L>
Debug formatting for UseAsyncHandle.
Source§impl<T, L> Default for UseAsyncHandle<T, L>
Default-construction for UseAsyncHandle.
impl<T, L> Default for UseAsyncHandle<T, L>
Default-construction for UseAsyncHandle.
Source§fn default() -> Self
fn default() -> Self
Constructs a default UseAsyncHandle value.