use std::{panic, sync::mpsc, thread, time::Duration};
pub(crate) fn assert_send<T: Send>(_t: &T) {}
pub(crate) fn assert_sync<T: Sync>(_t: &T) {}
pub(crate) fn assert_clone<T: Clone>(_t: &T) {}
pub(crate) fn with_timeout<T: Send + 'static>(f: impl FnOnce() -> T + Send + 'static) -> T {
let (tx, rx) = mpsc::channel();
let handle = thread::spawn(move || tx.send(f()));
match rx.recv_timeout(Duration::from_secs(10)) {
Ok(res) => res,
Err(mpsc::RecvTimeoutError::Timeout) => {
panic!("timed out waiting for a future that should have completed")
}
Err(mpsc::RecvTimeoutError::Disconnected) => match handle.join() {
Err(payload) => panic::resume_unwind(payload),
Ok(_) => panic!("helper thread finished without handing back a result"),
},
}
}