use crate::notification::NotificationResponse;
use std::{
collections::HashMap,
sync::{Arc, Condvar, LazyLock, Mutex, atomic::AtomicBool},
};
pub(crate) struct PendingEntry {
pub(crate) result: Mutex<NotificationResponse>,
pub(crate) done: AtomicBool,
pub(crate) condvar: Condvar,
pub(crate) delivered: Mutex<bool>,
pub(crate) delivered_cv: Condvar,
}
pub(crate) static PENDING: LazyLock<Mutex<HashMap<[u8; 16], Arc<PendingEntry>>>> =
LazyLock::new(|| Mutex::new(HashMap::new()));
pub(crate) fn pending() -> &'static Mutex<HashMap<[u8; 16], Arc<PendingEntry>>> {
&PENDING
}
pub(crate) struct PendingGuard {
pub(crate) id: [u8; 16],
}
impl Drop for PendingGuard {
fn drop(&mut self) {
pending().lock().unwrap().remove(&self.id);
}
}