[−][src]Struct async_notify::Notify
Notify a single task to wake up.
Notify
provides a basic mechanism to notify a single task of an event.
Notify
itself does not carry any data. Instead, it is to be used to signal
another task to perform an operation.
If notify()
is called before notified().await
, then the next call to
notified().await
will complete immediately, consuming the permit. Any
subsequent calls to notified().await
will wait for a new permit.
If notify()
is called multiple times before notified().await
, only a
single permit is stored. The next call to notified().await
will
complete immediately, but the one after will wait for a new permit.
Examples
Basic usage.
use async_notify::Notify; #[async_std::main] async fn main() { let notify = Notify::new(); let notify2 = notify.clone(); async_std::task::spawn(async move { notify2.notified().await; println!("received notification"); }); println!("sending notification"); notify.notify(); }
Methods
impl Notify
[src]
Like tokio Notify, this is a async-std version Notify and implement Clone.
pub fn new() -> Self
[src]
pub fn notify(&self)
[src]
Notifies a waiting task
If a task is currently waiting, that task is notified. Otherwise, a
permit is stored in this Notify
value and the next call to
notified().await
will complete immediately consuming the permit made
available by this call to notify()
.
At most one permit may be stored by Notify
. Many sequential calls to
notify
will result in a single permit being stored. The next call to
notified().await
will complete immediately, but the one after that
will wait.
Examples
use async_notify::Notify; #[async_std::main] async fn main() { let notify = Notify::new(); let notify2 = notify.clone(); async_std::task::spawn(async move { notify2.notified().await; println!("received notification"); }); println!("sending notification"); notify.notify(); }
pub async fn notified<'_>(&'_ self)
[src]
Wait for a notification.
Each Notify
value holds a single permit. If a permit is available from
an earlier call to notify()
, then notified().await
will complete
immediately, consuming that permit. Otherwise, notified().await
waits
for a permit to be made available by the next call to notify()
.
Examples
use async_notify::Notify; #[async_std::main] async fn main() { let notify = Notify::new(); let notify2 = notify.clone(); async_std::task::spawn(async move { notify2.notified().await; println!("received notification"); }); println!("sending notification"); notify.notify(); }
Trait Implementations
impl Clone for Notify
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for Notify
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Notify
impl Send for Notify
impl Sync for Notify
impl Unpin for Notify
impl !UnwindSafe for Notify
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,