pub async fn try_with_timeout<T, E, Fut>(
duration: Duration,
future: Fut,
) -> TimeoutResult<T, E>Expand description
Executes an async operation with a timeout, returning a TimeoutResult.
Unlike panic-on-timeout helpers, this function doesn’t panic on timeout but returns a structured result that the caller can handle.
§Example
ⓘ
use error_rail::async_ext::try_with_timeout;
use std::time::Duration;
match try_with_timeout(Duration::from_secs(5), fetch_data()).await {
TimeoutResult::Ok(data) => println!("Got data: {:?}", data),
TimeoutResult::Err(e) => println!("Error: {}", e.error_chain()),
TimeoutResult::Timeout(d) => println!("Timed out after {:?}", d),
}