pub struct Notify { /* private fields */ }
Expand description
Notifies a single task to wake up.
§Examples
Usage using tokio
as an example executor:
use std::sync::Arc;
use asyncsync::Notify;
#[tokio::main]
async fn main() {
let notify = Arc::new(Notify::new());
let clone = notify.clone();
let handle = tokio::task::spawn(async move {
clone.notified().await;
println!("Received notification");
});
notify.notify_one();
handle.await.unwrap();
}
Implementations§
Source§impl Notify
impl Notify
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Notifies all currently waiting tasks.
Note that notify_all
will only wake up all currently waiting tasks and not store any
notification for future tasks. If there are no tasks waiting, notify_all
does nothing.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Notifies a single waiting task.
If there are no task waiting, a notification is stored and the next waiting task will complete immediately.
Trait Implementations§
impl Send for Notify
impl Sync for Notify
Auto Trait Implementations§
impl !Freeze for Notify
impl RefUnwindSafe for Notify
impl Unpin for Notify
impl UnwindSafe for Notify
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more