pub struct Notify { /* private fields */ }Expand description
Wakes tasks waiting for an event that carries no value.
notify_one wakes the oldest waiter, or, when
nobody waits, stores one permit that the next
notified consumes at once, so a notification sent
just before the wait is not lost. notify_last is
the same for the newest waiter.
notify_waiters wakes every waiter that exists
when it is called and stores nothing.
A Notified future receives notify_waiters calls made any time
after it was created, even before it is first polled. It receives
notify_one and notify_last only once it is polled or
enabled.
use nuclei::sync::Notify;
use std::future::Future;
use std::pin::pin;
use std::task::{Context, Poll, Waker};
let notify = Notify::new();
notify.notify_one();
let mut cx = Context::from_waker(Waker::noop());
let waiting = pin!(notify.notified());
assert!(waiting.poll(&mut cx).is_ready(), "the stored permit is consumed");Implementations§
Source§impl Notify
impl Notify
Sourcepub const fn const_new() -> Self
pub const fn const_new() -> Self
A Notify with nobody waiting and no stored permit, usable in a
static.
Sourcepub fn notified(&self) -> Notified<'_> ⓘ
pub fn notified(&self) -> Notified<'_> ⓘ
A future that completes on the next notification.
It is guaranteed to receive notify_waiters calls from the moment it
is created, polled or not. It receives notify_one and notify_last
from its first poll, or its first call to
enable.
Sourcepub fn notified_owned(self: Arc<Self>) -> OwnedNotified ⓘ
pub fn notified_owned(self: Arc<Self>) -> OwnedNotified ⓘ
notified through an Arc, so the future can
outlive the borrow and move between tasks.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Wakes the oldest waiter, or stores a permit when nobody waits. At most one permit is stored.
Sourcepub fn notify_last(&self)
pub fn notify_last(&self)
Wakes the newest waiter, or stores a permit when nobody waits: as
notify_one, but for the waiter that queued last
instead of the one that queued first.
Sourcepub fn notify_waiters(&self)
pub fn notify_waiters(&self)
Wakes every task waiting now: every Notified created before this
call, whether or not it has been polled. Stores no permit.