#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

#95 in #await

Download history 5279/week @ 2024-03-04 3475/week @ 2024-03-11 5226/week @ 2024-03-18 4942/week @ 2024-03-25 5095/week @ 2024-04-01 5096/week @ 2024-04-08 5354/week @ 2024-04-15 6756/week @ 2024-04-22 4931/week @ 2024-04-29 4391/week @ 2024-05-06 9009/week @ 2024-05-13 7586/week @ 2024-05-20 6040/week @ 2024-05-27 5500/week @ 2024-06-03 5546/week @ 2024-06-10 6158/week @ 2024-06-17

23,669 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–15MB
~156K SLoC