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:
- Caller initiates request, calls
arm_pending; state storesgeneration = N. - 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. - The old result arrives at the host driver. Driver calls
resolvewithgeneration = N; the state is atN + 1, so the state rejects the stale value. - The new result arrives. Driver calls
resolvewithgeneration = N + 1; the state accepts and transitions toReady { 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.
Ready
A result is ready and has not yet been consumed.
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>
impl<T> AsyncRequestState<T>
Sourcepub fn is_pending(&self) -> bool
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.
Sourcepub fn generation(&self) -> Option<u64>
pub fn generation(&self) -> Option<u64>
Current request generation, if any. Returns None for
Idle/Interrupted.
Sourcepub fn arm_pending(&mut self, generation: u64) -> Selfwhere
T: Clone,
pub fn arm_pending(&mut self, generation: u64) -> Selfwhere
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).
Sourcepub fn resolve(&mut self, generation: u64, value: T) -> bool
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.
Trait Implementations§
Source§impl<T: Clone> Clone for AsyncRequestState<T>
impl<T: Clone> Clone for AsyncRequestState<T>
Source§impl<T: Debug> Debug for AsyncRequestState<T>
impl<T: Debug> Debug for AsyncRequestState<T>
Source§impl<T> Default for AsyncRequestState<T>
impl<T> Default for AsyncRequestState<T>
Source§impl<'de, T> Deserialize<'de> for AsyncRequestState<T>where
T: Deserialize<'de>,
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>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<T: Eq> Eq for AsyncRequestState<T>
Source§impl<T: PartialEq> PartialEq for AsyncRequestState<T>
impl<T: PartialEq> PartialEq for AsyncRequestState<T>
Source§impl<T> Serialize for AsyncRequestState<T>where
T: Serialize,
impl<T> Serialize for AsyncRequestState<T>where
T: Serialize,
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T> MemoryPayload for T
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.