use tokio::sync::Semaphore;
#[derive(Debug)]
pub struct Waiter {
done_semaphore: Semaphore,
}
impl Default for Waiter {
fn default() -> Self {
Self::new()
}
}
impl Waiter {
pub fn new() -> Self {
Self {
done_semaphore: Semaphore::new(0),
}
}
pub fn done(&self) {
self.done_semaphore.close();
}
pub async fn wait(&self) {
self.done_semaphore
.acquire()
.await
.expect_err("done semaphore is only closed, never has permits");
}
pub fn is_done(&self) -> bool {
self.done_semaphore.is_closed()
}
}
#[cfg(test)]
mod tests;