// Copyright 2025 Jonas Kruckenberg // // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be // copied, modified, or distributed except according to those terms. use arrayvec::ArrayVec; use core::task::Waker; const NUM_WAKERS: usize = 32; pub struct WakeBatch { inner: ArrayVec, } impl Default for WakeBatch { fn default() -> Self { Self::new() } } impl WakeBatch { pub const fn new() -> Self { Self { inner: ArrayVec::new_const(), } } /// Adds a [`Waker`] to the batch, returning `true` if the batch needs to be flushed because it /// is full. pub fn add_waker(&mut self, waker: Waker) -> bool { self.inner.push(waker); self.inner.is_full() } pub fn wake_all(&mut self) { for waker in self.inner.drain(..) { waker.wake(); } } pub fn len(&self) -> usize { self.inner.len() } pub fn is_empty(&self) -> bool { self.inner.is_empty() } }