#future #timeout #stream #await #async #delay #duration

futures-timeout

A utility that provides timeouts for futures and streams

2 releases

0.1.1 Jan 3, 2025
0.1.0 Apr 12, 2024

#574 in Asynchronous

Download history 353/week @ 2024-09-23 180/week @ 2024-09-30 304/week @ 2024-10-07 311/week @ 2024-10-14 91/week @ 2024-10-21 93/week @ 2024-10-28 119/week @ 2024-11-04 131/week @ 2024-11-11 166/week @ 2024-11-18 158/week @ 2024-11-25 140/week @ 2024-12-02 148/week @ 2024-12-09 279/week @ 2024-12-16 167/week @ 2024-12-23 269/week @ 2024-12-30 75/week @ 2025-01-06

799 downloads per month
Used in 2 crates

Apache-2.0 OR MIT

7KB
106 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
~38K SLoC