use core::task::Waker;
use heapless::Vec;
#[derive(Debug)]
pub struct MultiWakerRegistration<const N: usize> {
wakers: Vec<Waker, N>,
}
impl<const N: usize> MultiWakerRegistration<N> {
pub const fn new() -> Self {
Self { wakers: Vec::new() }
}
pub fn register(&mut self, w: &Waker) {
for w2 in &self.wakers {
if w.will_wake(w2) {
return;
}
}
if self.wakers.is_full() {
self.wake();
}
if self.wakers.push(w.clone()).is_err() && N == 0 {
panic!("tried to push a waker to a zero-length MultiWakerRegistration")
}
}
pub fn wake(&mut self) {
for w in self.wakers.drain(..) {
w.wake();
}
}
}