Skip to main content

AsyncRequestState

Enum AsyncRequestState 

Source
pub enum AsyncRequestState<T> {
    Idle,
    Pending {
        generation: u64,
    },
    Ready {
        generation: u64,
        value: T,
    },
    Interrupted,
}
Expand description

Frame-bounded state of a host-driven async request.

Generic over the result payload T. The enum is always fully deterministic — no internal threading, no hidden waiting. Hosts bridge their concrete async primitives (crossbeam / tokio / futures) into this state by calling the transition methods at frame boundaries.

The generation counter inside Pending and Ready lets callers distinguish a result for the current request from a late result for a request that has been superseded. The pattern:

  1. Caller initiates request, calls arm_pending; state stores generation = N.
  2. Caller initiates a newer request before the first completes; state moves to generation = N + 1, the old request’s result is still en route on the host driver’s side.
  3. The old result arrives at the host driver. Driver calls resolve with generation = N; the state is at N + 1, so the state rejects the stale value.
  4. The new result arrives. Driver calls resolve with generation = N + 1; the state accepts and transitions to Ready { generation: N + 1, value }.

Variants§

§

Idle

No request is in flight and no result is pending consumption.

§

Pending

A request has been kicked off. generation uniquely identifies this request; a late result with a smaller generation is stale and should be dropped.

Fields

§generation: u64
§

Ready

A result is ready and has not yet been consumed.

Fields

§generation: u64
§value: T
§

Interrupted

The pending request was interrupted: the driver dropped its sender, the request was explicitly cancelled, or the state was re-armed before the result arrived. Treat as “the work happened or didn’t, but don’t wait for a value”.

Implementations§

Source§

impl<T> AsyncRequestState<T>

Source

pub fn is_pending(&self) -> bool

true when a request is in flight — the caller has armed the state and is awaiting the driver’s resolution.

Source

pub fn is_ready(&self) -> bool

true when a result is ready to be consumed via take.

Source

pub fn generation(&self) -> Option<u64>

Current request generation, if any. Returns None for Idle/Interrupted.

Source

pub fn arm_pending(&mut self, generation: u64) -> Self
where T: Clone,

Transition to Pending with the supplied generation. Typically the caller tracks the next generation externally (e.g. an AtomicU64) and bumps on each new request so stale results from previous requests are rejected by resolve.

Returns the prior state so the caller can inspect whether a previous request was mid-flight (useful for logging / diagnostics).

Source

pub fn resolve(&mut self, generation: u64, value: T) -> bool

Deposit a result for a specific generation. If the state is Pending { generation == requested }, transitions to Ready { generation, value } and returns true. Otherwise (stale generation, idle, or already-ready), the value is discarded and returns false — the caller can use the return value for diagnostics.

Source

pub fn interrupt(&mut self)

Mark the request as interrupted. Idempotent.

Source

pub fn clear(&mut self)

Reset to Idle, discarding any in-flight request or pending result.

Source

pub fn take(&mut self) -> Option<T>

Consume a ready result. Returns Some(value) and resets the state to Idle if a result was ready; None otherwise (the state is left unchanged in that case).

Trait Implementations§

Source§

impl<T: Clone> Clone for AsyncRequestState<T>

Source§

fn clone(&self) -> Self

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: Debug> Debug for AsyncRequestState<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Default for AsyncRequestState<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T> Deserialize<'de> for AsyncRequestState<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Eq> Eq for AsyncRequestState<T>

Source§

impl<T: PartialEq> PartialEq for AsyncRequestState<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T> Serialize for AsyncRequestState<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for AsyncRequestState<T>

Auto Trait Implementations§

§

impl<T> Freeze for AsyncRequestState<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AsyncRequestState<T>
where T: RefUnwindSafe,

§

impl<T> Send for AsyncRequestState<T>
where T: Send,

§

impl<T> Sync for AsyncRequestState<T>
where T: Sync,

§

impl<T> Unpin for AsyncRequestState<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for AsyncRequestState<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for AsyncRequestState<T>
where T: UnwindSafe,

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T> MemoryPayload for T
where T: Clone + Debug + Serialize + for<'de> Deserialize<'de>,

Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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, !>

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.