use std::{
fmt,
io,
panic::{RefUnwindSafe, UnwindSafe},
rc::Rc,
time::Duration,
};
pub(crate) struct Parker {
inner: Rc<Inner>,
}
impl UnwindSafe for Parker {}
impl RefUnwindSafe for Parker {}
impl Parker {
pub(crate) fn new() -> Parker {
Parker {
inner: Rc::new(Inner {}),
}
}
pub(crate) fn park(&self) -> io::Result<bool> {
self.inner.park(|| None)
}
pub(crate) fn poll_io(&self, timeout: impl Fn() -> Option<Duration>) -> io::Result<bool> {
self.inner.park(timeout)
}
}
impl Drop for Parker {
fn drop(&mut self) {}
}
impl Default for Parker {
fn default() -> Parker {
Parker::new()
}
}
impl fmt::Debug for Parker {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Parker { .. }")
}
}
struct Inner {}
impl Inner {
fn park(&self, timeout: impl Fn() -> Option<Duration>) -> io::Result<bool> {
crate::executor().reactor().react(timeout)
}
}