#async #await #future #futures

smol-timeout

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

6 releases (breaking)

0.6.0 Oct 1, 2020
0.5.0 Sep 5, 2020
0.4.0 Aug 27, 2020
0.3.0 Aug 9, 2020
0.1.0 Jun 1, 2020

#1133 in Asynchronous

Download history 3349/week @ 2023-10-24 3434/week @ 2023-10-31 4874/week @ 2023-11-07 4610/week @ 2023-11-14 2967/week @ 2023-11-21 3233/week @ 2023-11-28 3153/week @ 2023-12-05 2525/week @ 2023-12-12 3125/week @ 2023-12-19 1974/week @ 2023-12-26 1754/week @ 2024-01-02 2139/week @ 2024-01-09 3259/week @ 2024-01-16 4978/week @ 2024-01-23 4347/week @ 2024-01-30 3764/week @ 2024-02-06

16,728 downloads per month
Used in 49 crates (29 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–13MB
~150K SLoC