Struct diatomic_waker::DiatomicWaker
source · pub struct DiatomicWaker { /* private fields */ }
Expand description
A primitive that can send or await notifications.
It is almost always preferable to use the WakeSink
and
WakeSource
which offer more convenience at the cost
of an allocation in an Arc
.
If allocation is not possible or desirable, the
sink_ref
method can be used to create a
WakeSinkRef
handle and one or more
WakeSourceRef
s, the non-owned
counterparts to WakeSink
and WakeSource
.
Finally, DiatomicWaker
exposes unsafe
methods that can be used to create
custom synchronization primitives.
Implementations§
source§impl DiatomicWaker
impl DiatomicWaker
sourcepub const fn new() -> Self
Available on non-diatomic_waker_loom
only.
pub const fn new() -> Self
diatomic_waker_loom
only.Creates a new DiatomicWaker
.
sourcepub fn sink_ref(&mut self) -> WakeSinkRef<'_>
pub fn sink_ref(&mut self) -> WakeSinkRef<'_>
Returns a sink with a lifetime bound to this DiatomicWaker
.
This mutably borrows the waker, thus ensuring that at most one associated sink can be active at a time.
sourcepub fn notify(&self)
pub fn notify(&self)
Sends a notification if a waker is registered.
This automatically unregisters any waker that may have been previously registered.
sourcepub unsafe fn register(&self, waker: &Waker)
pub unsafe fn register(&self, waker: &Waker)
Registers a new waker.
Registration is lazy: the waker is cloned only if it differs from the last registered waker (note that the last registered waker is cached even if it was unregistered).
§Safety
The register
, unregister
and wait_until
methods cannot be used
concurrently from multiple threads.
sourcepub unsafe fn unregister(&self)
pub unsafe fn unregister(&self)
Unregisters the waker.
After the waker is unregistered, subsequent calls to notify
will be
ignored.
Note that the previously-registered waker (if any) remains cached.
§Safety
The register
, unregister
and wait_until
methods cannot be used
concurrently from multiple threads.
sourcepub unsafe fn wait_until<P, T>(&self, predicate: P) -> WaitUntil<'_, P, T> ⓘ
pub unsafe fn wait_until<P, T>(&self, predicate: P) -> WaitUntil<'_, P, T> ⓘ
Returns a future that can be await
ed until the provided predicate
returns a value.
The predicate is checked each time a notification is received.
§Safety
The register
, unregister
and wait_until
methods cannot be used
concurrently from multiple threads.