/// Notifies all waiting tasks.
///
/// If a task is currently waiting, that task is notified. Unlike with
/// `notify_one()`, no permit is stored to be used by the next call to
/// `notified().await`. The purpose of this method is to notify all
/// already registered waiters. Registering for notification is done by
/// acquiring an instance of the `Notified` future via calling `notified()`.
///
/// # Examples
///
/// ```
/// use tokio::sync::Notify;
/// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
///     let notify = Arc::new(Notify::new());
///     let notify2 = notify.clone();
///
///     let notified1 = notify.notified();
///     let notified2 = notify.notified();
///
///     let handle = tokio::spawn(async move {
///         println!("sending notifications");
///         notify2.notify_waiters();
///     });
///
///     notified1.await;
///     notified2.await;
///     println!("received notifications");
/// }
/// ```
Notifies all waiting tasks.
If a task is currently waiting, that task is notified. Unlike with
`notify_one()`, no permit is stored to be used by the next call to
`notified().await`. The purpose of this method is to notify all
already registered waiters. Registering for notification is done by
acquiring an instance of the `Notified` future via calling `notified()`.
Notifies all waiting tasks . If a task is currently waiting that task is notified . Unlike with ` notify_one () ` no permit is stored to be used by the next call to ` notified () . await ` . The purpose of this method is to notify all already registered waiters . Registering for notification is done by acquiring an instance of the ` Notified ` future via calling ` notified () ` .
pub fn notify_waiters(&self) {
        let mut wakers = WakeList::new();
        // There are waiters, the lock must be acquired to notify.
        let mut waiters = self.waiters.lock();
        // The state must be reloaded while the lock is held. The state may only
        // transition out of WAITING while the lock is held.
        let curr = self.state.load(SeqCst);
        if matches!(get_state(curr), EMPTY | NOTIFIED) {
            // There are no waiting tasks. All we need to do is increment the
            // number of times this method was called.
            atomic_inc_num_notify_waiters_calls(&self.state);
            return;
        }
        // At this point, it is guaranteed that the state will not
        // concurrently change, as holding the lock is required to
        // transition **out** of `WAITING`.
        'outer: loop {
            while wakers.can_push() {
                match waiters.pop_back() {
                    Some(mut waiter) => {
                        // Safety: `waiters` lock is still held.
                        let waiter = unsafe { waiter.as_mut() };
                        assert!(waiter.notified.is_none());
                        waiter.notified = Some(NotificationType::AllWaiters);
                        if let Some(waker) = waiter.waker.take() {
                            wakers.push(waker);
                        }
                    }
                    None => {
                        break 'outer;
                    }
                }
            }
            drop(waiters);
            wakers.wake_all();
            // Acquire the lock again.
            waiters = self.waiters.lock();
        }
        // All waiters will be notified, the state must be transitioned to
        // `EMPTY`. As transitioning **from** `WAITING` requires the lock to be
        // held, a `store` is sufficient.
        let new = set_state(inc_num_notify_waiters_calls(curr), EMPTY);
        self.state.store(new, SeqCst);
        // Release the lock before notifying
        drop(waiters);
        wakers.wake_all();
    }
pub fn notify_waiters ( & self ) { let mut wakers = WakeList :: new ( ) ; // There are waiters, the lock must be acquired to notify. let mut waiters = self . waiters . lock ( ) ; // The state must be reloaded while the lock is held. The state may only // transition out of WAITING while the lock is held. let curr = self . state . load ( SeqCst ) ; if matches ! ( get_state ( curr ) EMPTY NOTIFIED ) { // There are no waiting tasks. All we need to do is increment the // number of times this method was called. atomic_inc_num_notify_waiters_calls ( & self . state ) ; return ; } // At this point, it is guaranteed that the state will not // concurrently change, as holding the lock is required to // transition **out** of `WAITING`. ' outer : loop { while wakers . can_push ( ) { match waiters . pop_back ( ) { Some ( mut waiter ) => { // Safety: `waiters` lock is still held. let waiter = unsafe { waiter . as_mut ( ) } ; assert ! ( waiter notified is_none ( ) ) ; waiter . notified = Some ( NotificationType :: AllWaiters ) ; if let Some ( waker ) = waiter . waker . take ( ) { wakers . push ( waker ) ; } } None => { break ' outer ; } } } drop ( waiters ) ; wakers . wake_all ( ) ; // Acquire the lock again. waiters = self . waiters . lock ( ) ; } // All waiters will be notified, the state must be transitioned to // `EMPTY`. As transitioning **from** `WAITING` requires the lock to be // held, a `store` is sufficient. let new = set_state ( inc_num_notify_waiters_calls ( curr ) , EMPTY ) ; self . state . store ( new , SeqCst ) ; // Release the lock before notifying drop ( waiters ) ; wakers . wake_all ( ) ; }
Notifies all waiting tasks.
Notifies all waiting tasks .
&self
examples
```
use tokio::sync::Notify;
use std::sync::Arc.
` ` ` use tokio :: sync :: Notify ; use std :: sync :: Arc .
[tokio::main]
async fn main() {
let notify = Arc::new(Notify::new());
let notify2 = notify.clone().

let notified1 = notify.notified();
let notified2 = notify.notified().

let handle = tokio::spawn(async move {
println!("sending notifications");
notify2.notify_waiters();
}).

notified1.await;
notified2.await;
println!("received notifications");
}
```
async fn main () { let notify = Arc :: new ( Notify :: new () ) ; let notify2 = notify . clone () . let notified1 = notify . notified () ; let notified2 = notify . notified () . let handle = tokio :: spawn ( async move { println! ( " sending notifications " ) ; notify2 . notify_waiters () ; } ) . notified1 . await ; notified2 . await ; println! ( " received notifications " ) ; } ` ` `