Skip to main content

ras_cdp/infrastructure/
timeout.rs

1use std::future::Future;
2use std::time::Duration;
3
4use ras_errors::AppError;
5use tokio::time::timeout;
6
7pub async fn within<T, F>(label: &str, dur: Duration, fut: F) -> Result<T, AppError>
8where
9    F: Future<Output = Result<T, AppError>>,
10{
11    match timeout(dur, fut).await {
12        Ok(inner) => inner,
13        Err(_) => Err(AppError::CdpTimeout(format!(
14            "{label} exceeded {}ms",
15            dur.as_millis()
16        ))),
17    }
18}