Skip to main content

run_with_timeout

Function run_with_timeout 

Source
pub async fn run_with_timeout<F, T>(
    name: impl Into<String>,
    timeout: Duration,
    fut: F,
) -> CheckResult
where F: Future<Output = T>,
Expand description

Run a future with a hard timeout. Produces a CheckResult tagged async.

If the future completes before the timeout, the verdict is Pass and the duration is recorded.

If the future does not complete in time, the verdict is Fail with severity Error. The future itself is dropped (cancelled) when the timeout expires.

The returned CheckResult carries numeric Evidence for timeout_ms and (on the pass path) elapsed_ms.

ยงExample

use dev_async::run_with_timeout;
use std::time::Duration;

let check = run_with_timeout("op", Duration::from_millis(50), async {}).await;
assert!(check.has_tag("async"));