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

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

#93 in #await

Download history 2158/week @ 2023-12-09 3520/week @ 2023-12-16 1806/week @ 2023-12-23 1836/week @ 2023-12-30 1897/week @ 2024-01-06 3160/week @ 2024-01-13 4061/week @ 2024-01-20 4498/week @ 2024-01-27 4513/week @ 2024-02-03 4495/week @ 2024-02-10 6922/week @ 2024-02-17 5489/week @ 2024-02-24 5132/week @ 2024-03-02 3521/week @ 2024-03-09 4905/week @ 2024-03-16 4883/week @ 2024-03-23

19,567 downloads per month
Used in 48 crates (32 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–14MB
~156K SLoC