pub struct Notify { /* private fields */ }
Expand description
Notifies one task or all attached tasks to wakeup.
notify_one and notified().await behave similar to Thread::unpark and thread::park except that notified().await will not be waked up spuriously. One could assume that there is at most one permit associated with Notify. notified().await will block current task unless or until the permit is available to consume. notify_one release the permit for notified().await to acquire, it will wake up Notified in FIFO order if there are multiple Notifieds blocking for the permit. The order of Notifieds are the order of notified().await or Notified::enable() whichever first.
notify_all, on the other hand, will wake up all attached Notifieds and start a fresh new round for notify_one with no permit. Notify::notified()s are attached by default, one could use Notified::detach to detach from rounds of Notify until Notified::enable or future polling.
§Differences with tokio
- tokio::sync::Notify::notify_all() does not clear permit from notify_one.
- tokio does not have Notified::detach().
Implementations§
Source§impl Notify
impl Notify
Sourcepub fn notified(&self) -> Notified<'_> ⓘ
pub fn notified(&self) -> Notified<'_> ⓘ
Constructs a attached Notified to consume permit from Notify::notify_one.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Notifies one waiting task or stores a permit to consume in case of no waiting task.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Notifies all attached Notifieds and starts a fresh new round with no permit.