#future #async #async-await

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

#111 in #async-await

Download history 1438/week @ 2025-10-02 1399/week @ 2025-10-09 1949/week @ 2025-10-16 1764/week @ 2025-10-23 2061/week @ 2025-10-30 2048/week @ 2025-11-06 1579/week @ 2025-11-13 1739/week @ 2025-11-20 1755/week @ 2025-11-27 1855/week @ 2025-12-04 2076/week @ 2025-12-11 1641/week @ 2025-12-18 1416/week @ 2025-12-25 1686/week @ 2026-01-01 1247/week @ 2026-01-08 2305/week @ 2026-01-15

6,862 downloads per month
Used in 59 crates (37 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

~2.3–6.5MB
~147K SLoC