#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

#732 in Asynchronous

Download history 702/week @ 2022-06-11 707/week @ 2022-06-18 571/week @ 2022-06-25 243/week @ 2022-07-02 247/week @ 2022-07-09 324/week @ 2022-07-16 489/week @ 2022-07-23 951/week @ 2022-07-30 785/week @ 2022-08-06 787/week @ 2022-08-13 1152/week @ 2022-08-20 586/week @ 2022-08-27 731/week @ 2022-09-03 731/week @ 2022-09-10 897/week @ 2022-09-17 781/week @ 2022-09-24

3,226 downloads per month
Used in 33 crates (20 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

~1MB
~15K SLoC