#timeout #delay #async-await #duration #block #futures-timer

futures-timeout

A utility that provides timeouts for futures and streams

3 releases

0.1.2 Mar 5, 2025
0.1.1 Jan 3, 2025
0.1.0 Apr 12, 2024

#319 in Asynchronous

Download history 152/week @ 2024-11-29 126/week @ 2024-12-06 220/week @ 2024-12-13 220/week @ 2024-12-20 134/week @ 2024-12-27 264/week @ 2025-01-03 75/week @ 2025-01-10 134/week @ 2025-01-17 92/week @ 2025-01-24 191/week @ 2025-01-31 92/week @ 2025-02-07 100/week @ 2025-02-14 146/week @ 2025-02-21 446/week @ 2025-02-28 181/week @ 2025-03-07 134/week @ 2025-03-14

935 downloads per month
Used in 2 crates

Apache-2.0 OR MIT

10KB
118 lines

futures-timeout

A simple utility that provides timeouts for futures and streams, which utilizes futures-timer. This library is compatible with wasm32-unknown-unknown target.

fn main() {
    futures::executor::block_on(async move {
        use std::time::Duration;
        use futures_timeout::TimeoutExt;
        
        let fut = async {
            futures_timer::Delay::new(Duration::from_secs(30)).await;
        };

        fut.timeout(Duration::from_secs(5))
            .await
            .expect_err("should fail");
    });
}

Dependencies

~1–2MB
~37K SLoC