#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

#398 in Asynchronous

Download history 88/week @ 2024-10-26 109/week @ 2024-11-02 143/week @ 2024-11-09 142/week @ 2024-11-16 170/week @ 2024-11-23 152/week @ 2024-11-30 145/week @ 2024-12-07 240/week @ 2024-12-14 180/week @ 2024-12-21 261/week @ 2024-12-28 130/week @ 2025-01-04 102/week @ 2025-01-11 131/week @ 2025-01-18 70/week @ 2025-01-25 204/week @ 2025-02-01 64/week @ 2025-02-08

505 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
~37K SLoC