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

smol-timeout

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

7 releases (breaking)

new 0.6.1 Mar 4, 2025
0.6.0 Oct 1, 2020
0.5.0 Sep 5, 2020
0.4.0 Aug 27, 2020
0.1.0 Jun 1, 2020

#108 in #await

Download history 4302/week @ 2024-11-05 2922/week @ 2024-11-12 2907/week @ 2024-11-19 2480/week @ 2024-11-26 2191/week @ 2024-12-03 2851/week @ 2024-12-10 2928/week @ 2024-12-17 1056/week @ 2024-12-24 1150/week @ 2024-12-31 1817/week @ 2025-01-07 2527/week @ 2025-01-14 2309/week @ 2025-01-21 1918/week @ 2025-01-28 3168/week @ 2025-02-04 2510/week @ 2025-02-11 5/week @ 2025-02-18

7,973 downloads per month
Used in 52 crates (33 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–11MB
~142K SLoC