mod queue;
mod set;
use std::cell::Cell;
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
use std::rc::Weak;
use std::task::Waker;
pub use self::queue::ScheduledWakerQueue;
pub use self::set::WakerSet;
#[derive(Clone, Debug)]
struct WakerEntry(pub Weak<Cell<Option<Waker>>>);
impl PartialEq for WakerEntry {
fn eq(&self, other: &Self) -> bool {
self.0.ptr_eq(&other.0)
}
}
impl Eq for WakerEntry {}
impl Hash for WakerEntry {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.as_ptr().addr().hash(state);
}
}
impl PartialOrd for WakerEntry {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for WakerEntry {
fn cmp(&self, other: &Self) -> Ordering {
self.0.as_ptr().addr().cmp(&other.0.as_ptr().addr())
}
}
impl WakerEntry {
#[must_use]
pub fn is_alive(&self) -> bool {
self.0.upgrade().is_some_and(|cell| {
let waker = cell.take();
let is_alive = waker.is_some();
cell.set(waker);
is_alive
})
}
}