run_with_timeout/
run_with_timeout.rs1use std::time::Duration;
14
15use dev_async::run_with_timeout;
16
17#[tokio::main(flavor = "current_thread")]
18async fn main() {
19 let fast = run_with_timeout("fast_op", Duration::from_millis(500), async {
20 tokio::time::sleep(Duration::from_millis(10)).await;
21 })
22 .await;
23 println!(
24 "fast: {:?} tags={:?} duration={:?}ms",
25 fast.verdict, fast.tags, fast.duration_ms
26 );
27
28 let hung = run_with_timeout("hung_op", Duration::from_millis(50), async {
29 tokio::time::sleep(Duration::from_secs(60)).await;
30 })
31 .await;
32 println!(
33 "hung: {:?} tags={:?} severity={:?}",
34 hung.verdict, hung.tags, hung.severity
35 );
36 if let Some(detail) = &hung.detail {
37 println!(" detail: {}", detail);
38 }
39}