pal_async/
waker.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Utilities for wakers.

use std::task::Waker;

/// A list of wakers that are ready to be woken.
#[must_use]
#[derive(Debug, Default)]
pub struct WakerList(Vec<Waker>);

impl WakerList {
    /// Wakes all the wakers.
    pub fn wake(&mut self) {
        for waker in self.0.drain(..) {
            waker.wake();
        }
    }

    #[cfg_attr(not(windows), expect(dead_code))]
    pub fn push(&mut self, waker: Waker) {
        self.0.push(waker);
    }
}

impl Extend<Waker> for WakerList {
    fn extend<T: IntoIterator<Item = Waker>>(&mut self, iter: T) {
        self.0.extend(iter);
    }
}

impl FromIterator<Waker> for WakerList {
    fn from_iter<T: IntoIterator<Item = Waker>>(iter: T) -> Self {
        Self(iter.into_iter().collect())
    }
}