#async-await #future #await #async #async-io

smol-timeout2

A way to poll a future until it or a timer completes

1 unstable release

0.6.1 Aug 28, 2024

#1290 in Asynchronous

Download history 93/week @ 2024-08-24 339/week @ 2024-08-31 391/week @ 2024-09-07 336/week @ 2024-09-14 165/week @ 2024-09-21 131/week @ 2024-09-28 114/week @ 2024-10-05 180/week @ 2024-10-12 177/week @ 2024-10-19 189/week @ 2024-10-26 274/week @ 2024-11-02 124/week @ 2024-11-09 142/week @ 2024-11-16

777 downloads per month
Used in 9 crates (3 directly)

MPL-2.0 license

12KB

smol-timeout

img img img

A way to poll a future until it or a timer completes.

Example

use async_io::Timer;
use smol_timeout::TimeoutExt;
use std::time::Duration;

let foo = async {
    Timer::new(Duration::from_millis(250)).await;
    24
};

let foo = foo.timeout(Duration::from_millis(100));
assert_eq!(foo.await, None);

let bar = async {
    Timer::new(Duration::from_millis(100)).await;
    42
};

let bar = bar.timeout(Duration::from_millis(250));
assert_eq!(bar.await, Some(42));

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Dependencies

~3–11MB
~134K SLoC