3 releases

0.6.3 May 30, 2025
0.6.2 Nov 20, 2024
0.6.1 Nov 20, 2024

#977 in Asynchronous

Download history 63/week @ 2025-05-21 167/week @ 2025-05-28 3/week @ 2025-06-18 2/week @ 2025-07-09 15/week @ 2025-08-13 22/week @ 2025-08-20 5/week @ 2025-08-27 15/week @ 2025-09-03

57 downloads per month
Used in 4 crates

MPL-2.0 license

13KB
53 lines

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–16MB
~157K SLoC