#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

#545 in Asynchronous

Download history 1400/week @ 2022-11-29 1149/week @ 2022-12-06 572/week @ 2022-12-13 784/week @ 2022-12-20 558/week @ 2022-12-27 427/week @ 2023-01-03 1372/week @ 2023-01-10 1856/week @ 2023-01-17 2452/week @ 2023-01-24 3430/week @ 2023-01-31 2223/week @ 2023-02-07 2754/week @ 2023-02-14 2289/week @ 2023-02-21 2178/week @ 2023-02-28 2614/week @ 2023-03-07 1885/week @ 2023-03-14

9,590 downloads per month
Used in 36 crates (22 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

~1–6MB
~91K SLoC