esp_hal/
asynch.rs

1//! Asynchronous utilities.
2use core::task::Waker;
3
4use embassy_sync::waitqueue::GenericAtomicWaker;
5
6use crate::sync::RawMutex;
7
8/// Utility struct to register and wake a waker.
9pub struct AtomicWaker {
10    waker: GenericAtomicWaker<RawMutex>,
11}
12
13impl AtomicWaker {
14    /// Create a new `AtomicWaker`.
15    #[allow(clippy::new_without_default)]
16    pub const fn new() -> Self {
17        Self {
18            waker: GenericAtomicWaker::new(RawMutex::new()),
19        }
20    }
21
22    delegate::delegate! {
23        to self.waker {
24            /// Register a waker. Overwrites the previous waker, if any.
25            pub fn register(&self, w: &Waker);
26            /// Wake the registered waker, if any.
27            pub fn wake(&self);
28        }
29    }
30}