Skip to main content

UseAsyncHandle

Struct UseAsyncHandle 

Source
pub struct UseAsyncHandle<T, L>
where T: Clone + PartialEq + 'static, L: Clone + PartialEq + HasLoadingHint + 'static,
{ /* 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 current AsyncState<T, L> (matches what the user should match on in html!).
  • 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 its Ok/Err branches 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>
where T: Clone + PartialEq + 'static, L: Clone + PartialEq + HasLoadingHint + 'static,

Source

pub fn state(&self) -> AsyncState<T, L>

Returns the current reactive state.

§Returns
  • AsyncState<T, L> - The current AsyncState, owned.
Source

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> - A AsyncState<T, L> parameter.
Source

pub fn refetch<F, Fut, E>(&self, factory: F)
where F: FnOnce() -> Fut + 'static, Fut: Future<Output = Result<T, E>> + 'static, E: Into<String> + 'static,

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>
where T: Clone + PartialEq + 'static, L: Clone + PartialEq + HasLoadingHint + 'static,

Source

pub fn get_inner(&self) -> &usize

Source

pub fn get_mut_inner(&mut self) -> &mut usize

Source

pub fn set_inner(&mut self, val: usize) -> &mut Self

Source

pub fn get__marker(&self) -> &PhantomData<fn() -> (T, L)>

Source

pub fn get_mut__marker(&mut self) -> &mut PhantomData<fn() -> (T, L)>

Source

pub fn set__marker(&mut self, val: PhantomData<fn() -> (T, L)>) -> &mut Self

Trait Implementations§

Source§

impl<T, L> Clone for UseAsyncHandle<T, L>
where T: Clone + PartialEq + 'static + Clone, L: Clone + PartialEq + HasLoadingHint + 'static + Clone,

Source§

fn clone(&self) -> UseAsyncHandle<T, L>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, L> Copy for UseAsyncHandle<T, L>
where T: Clone + PartialEq + 'static + Copy, L: Clone + PartialEq + HasLoadingHint + 'static + Copy,

Source§

impl<T, L> Debug for UseAsyncHandle<T, L>
where T: Clone + PartialEq + 'static, L: Clone + PartialEq + HasLoadingHint + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the UseAsyncHandle via the supplied formatter.

§Arguments
  • &mut core::fmt::Formatter<'_> - The formatter receiving the formatted output.
§Returns
  • core::fmt::Result - Result of the formatting operation.
Source§

impl<T, L> Default for UseAsyncHandle<T, L>
where T: Clone + PartialEq + 'static, L: Clone + PartialEq + HasLoadingHint + 'static,

Source§

fn default() -> Self

Constructs a default UseAsyncHandle value.

Auto Trait Implementations§

§

impl<T, L> Freeze for UseAsyncHandle<T, L>
where PhantomData<fn() -> (T, L)>: Freeze,

§

impl<T, L> RefUnwindSafe for UseAsyncHandle<T, L>

§

impl<T, L> Send for UseAsyncHandle<T, L>
where PhantomData<fn() -> (T, L)>: Send,

§

impl<T, L> Sync for UseAsyncHandle<T, L>
where PhantomData<fn() -> (T, L)>: Sync,

§

impl<T, L> Unpin for UseAsyncHandle<T, L>
where PhantomData<fn() -> (T, L)>: Unpin,

§

impl<T, L> UnsafeUnpin for UseAsyncHandle<T, L>

§

impl<T, L> UnwindSafe for UseAsyncHandle<T, L>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more