smol-timeout2

Crates.iosmol-timeout2
lib.rssmol-timeout2
version0.6.1
sourcesrc
created_at2024-08-28 19:45:27.167868
updated_at2024-08-28 19:45:27.167868
descriptionA way to poll a future until it or a timer completes.
homepagehttps://github.com/nullchinchilla/smol-timeout2
repositoryhttps://github.com/nullchinchilla/smol-timeout2
max_upload_size
id1355187
size31,252
Eric Tung (nullchinchilla)

documentation

https://docs.rs/smol-timeout2

README

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/.

Commit count: 0

cargo fmt