Struct Notify

Source
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

Implementations§

Source§

impl Notify

Source

pub fn new() -> Self

Constructs a new Notify.

Source

pub fn notified(&self) -> Notified<'_>

Constructs a attached Notified to consume permit from Notify::notify_one.

Source

pub fn notify_one(&self)

Notifies one waiting task or stores a permit to consume in case of no waiting task.

Source

pub fn notify_all(&self)

Notifies all attached Notifieds and starts a fresh new round with no permit.

Trait Implementations§

Source§

impl Default for Notify

Source§

fn default() -> Notify

Returns the “default value” for a type. Read more
Source§

impl Send for Notify

Source§

impl Sync for Notify

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.