pub struct ResultCell<T, W: Waiter, S: StateWord = AtomicU8> { /* private fields */ }Expand description
Single-producer, single-consumer completion cell for one unit of work.
The state word’s storage is a parameter (StateWord), so each caller keeps
the layout it needs; see the layout note.
Implementations§
Source§impl<T, W: Waiter, S: StateWord> ResultCell<T, W, S>
impl<T, W: Waiter, S: StateWord> ResultCell<T, W, S>
Sourcepub fn complete(&self, result: T)
pub fn complete(&self, result: T)
Publish the result, waking the parked waiter if one is registered.
Called exactly once by the producer; a second call is a no-op.
Sourcepub fn try_take_ready(&self) -> Option<T>
pub fn try_take_ready(&self) -> Option<T>
Take the result if the producer has published it.
Sourcepub fn try_take_observed_ready(&self) -> Option<T>
pub fn try_take_observed_ready(&self) -> Option<T>
Take the result only if a relaxed load already observed it, for a spin
loop that re-checks: the load is the hint, try_take_ready
is the decision.
Sourcepub fn is_completed(&self) -> bool
pub fn is_completed(&self) -> bool
Whether the producer has published a result.
Sourcepub fn has_registered_waiter(&self) -> bool
pub fn has_registered_waiter(&self) -> bool
Whether a waiter is parked and no result has been published yet.
The complement of is_completed would also
answer true before any registration, so this reports the waiting state
itself: it is what distinguishes a registration that took effect from
one that never ran.
Sourcepub unsafe fn register(&self, waiter: &W)
pub unsafe fn register(&self, waiter: &W)
Park a clone of waiter, or replace the parked one when
REPLACE_ON_REPEAT is set.
Registration retries until the state is settled, so the waiter is stored
from a clone and a failed publish transition costs only that clone. The
caller must re-check try_take_ready after this
returns: a complete that raced in before the registration does not wake,
because it saw no waiter. See the
module docs.
§Safety
The waiter cell has one writer at a time, so no other call to register
may run on this cell concurrently, and waiter.clone() must not reach
back into this cell. The cell has one consumer by construction (a blocking
join takes the handle by value; an async poll takes Pin<&mut Self>), and
the caller is that consumer.