#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

#158 in Asynchronous

Download history 292/week @ 2020-11-02 219/week @ 2020-11-09 292/week @ 2020-11-16 299/week @ 2020-11-23 231/week @ 2020-11-30 203/week @ 2020-12-07 199/week @ 2020-12-14 296/week @ 2020-12-21 227/week @ 2020-12-28 300/week @ 2021-01-04 331/week @ 2021-01-11 416/week @ 2021-01-18 317/week @ 2021-01-25 227/week @ 2021-02-01 206/week @ 2021-02-08 141/week @ 2021-02-15

2,855 downloads per month
Used in 5 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

~1MB
~16K SLoC