pub struct OnceSlot<T> { /* private fields */ }Expand description
A single-fire, wait-free async result cell.
The generalization of the PENDING-sentinel-AtomicI64 pattern used
elsewhere in this crate, for results that aren’t a plain integer. See
the module doc above for the exactly-once set contract.
Implementations§
Source§impl<T> OnceSlot<T>
impl<T> OnceSlot<T>
Sourcepub fn set(&self, value: T)
pub fn set(&self, value: T)
Complete this slot with value, waking whatever’s polling it.
Must be called at most once per OnceSlot.
Sourcepub fn poll(&self, cx: &Context<'_>) -> Poll<T>
pub fn poll(&self, cx: &Context<'_>) -> Poll<T>
Poll for completion, registering cx’s waker if not yet complete.
Both checks swap the pointer out (not just load) before
reconstructing the Box — polling again after an already-observed
Ready is not something callers are expected to do (standard
Future contract), but doing it anyway must not double-free, and
a load-then-Box::from_raw on the fast path would leave a
dangling non-null pointer behind for exactly that case.