#[cfg(test)]
use std::future::Future;
pub(crate) fn watchdog(timeout: std::time::Duration) -> tokio::sync::oneshot::Receiver<()> {
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
std::thread::spawn(move || {
std::thread::sleep(timeout);
let _ = tx.send(());
});
rx
}
#[cfg(test)]
pub(crate) async fn bounded<T>(millis: u64, fut: impl Future<Output = T>) -> Option<T> {
let rx = watchdog(std::time::Duration::from_millis(millis));
tokio::pin!(fut);
tokio::pin!(rx);
tokio::select! {
out = &mut fut => Some(out),
_ = &mut rx => None,
}
}