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