use std::time::{Duration, Instant};
#[cfg_attr(
not(windows),
allow(
dead_code,
reason = "the tokio teardowns read it outside tests; the proxy's wait is Windows-only"
)
)]
pub(crate) const LATE: Duration = Duration::from_secs(1);
#[derive(Debug, Clone, Copy)]
pub(crate) struct Due {
pub(crate) until: Instant,
pub(crate) after: Duration,
}
impl Due {
pub(crate) fn in_(after: Option<Duration>) -> Option<Due> {
after.map(|after| Due {
until: crate::wait::now() + after,
after,
})
}
}
pub(crate) fn wait_warning<S, R>(
mut state: S,
due: Option<Due>,
ended_by: impl FnOnce(&mut S, Instant) -> bool,
warn: impl FnOnce(Duration),
wait: impl FnOnce(S) -> R,
) -> R {
if let Some(due) = due {
if !ended_by(&mut state, due.until) {
warn(due.after);
}
}
wait(state)
}
#[cfg(test)]
#[path = "teardown_warn_tests.rs"]
mod teardown_warn_tests;