| Crates.io | smol-timeout |
| lib.rs | smol-timeout |
| version | 0.6.1 |
| created_at | 2020-06-01 23:51:56.436755+00 |
| updated_at | 2025-03-04 07:58:13.495596+00 |
| description | A way to poll a future until it or a timer completes. |
| homepage | https://github.com/r3v2d0g/smol-timeout |
| repository | https://github.com/r3v2d0g/smol-timeout |
| max_upload_size | |
| id | 248935 |
| size | 39,281 |
smol-timeoutA way to poll a future until it or a timer completes.
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));
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/.