use std::future::Future;
use std::time::Duration;
use tokio::time::timeout;
pub async fn with_timeout<T, F>(duration: Duration, label: &str, future: F) -> anyhow::Result<T>
where
F: Future<Output = anyhow::Result<T>>,
{
match timeout(duration, future).await {
Ok(result) => result,
Err(_) => {
anyhow::bail!("{label} timed out after {}s", duration.as_secs())
}
}
}