Skip to main content

Notify

Struct Notify 

Source
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

Source

pub const fn new() -> Self

A Notify with nobody waiting and no stored permit.

Source

pub const fn const_new() -> Self

A Notify with nobody waiting and no stored permit, usable in a static.

Source

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.

Source

pub fn notified_owned(self: Arc<Self>) -> OwnedNotified ⓘ

notified through an Arc, so the future can outlive the borrow and move between tasks.

Source

pub fn notify_one(&self)

Wakes the oldest waiter, or stores a permit when nobody waits. At most one permit is stored.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Notify

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Notify

Source§

fn default() -> Self

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

impl Drop for Notify

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

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.