Checkpoint

This commit is contained in:
Antonio Scandurra 2023-10-04 19:53:29 +02:00
parent 5aa45607eb
commit dc9a260425
11 changed files with 251 additions and 1194 deletions

View file

@ -1,18 +1,16 @@
use smol::future::FutureExt;
use std::{future::Future, time::Duration};
pub use util::*;
pub async fn timeout<F, T>(timeout: Duration, f: F) -> Result<T, ()>
where
F: Future<Output = T>,
{
let timer = async {
smol::Timer::after(timeout).await;
Err(())
};
let future = async move { Ok(f.await) };
timer.race(future).await
}
// pub async fn timeout<F, T>(timeout: Duration, f: F) -> Result<T, ()>
// where
// F: Future<Output = T>,
// {
// let timer = async {
// smol::Timer::after(timeout).await;
// Err(())
// };
// let future = async move { Ok(f.await) };
// timer.race(future).await
// }
#[cfg(any(test, feature = "test"))]
pub struct CwdBacktrace<'a>(pub &'a backtrace::Backtrace);