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

smol-timeout

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

7 releases (breaking)

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

#99 in #async-await

Download history 1641/week @ 2025-01-06 2645/week @ 2025-01-13 2251/week @ 2025-01-20 1760/week @ 2025-01-27 3245/week @ 2025-02-03 2481/week @ 2025-02-10 2716/week @ 2025-02-17 2764/week @ 2025-02-24 2453/week @ 2025-03-03 2612/week @ 2025-03-10 3298/week @ 2025-03-17 3643/week @ 2025-03-24 2687/week @ 2025-03-31 2169/week @ 2025-04-07 2120/week @ 2025-04-14 1935/week @ 2025-04-21

9,177 downloads per month
Used in 53 crates (34 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–12MB
~155K SLoC