1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#+OPTIONS: toc:nil
* ~smol-timeout~
[[https://github.com/r3v2d0g/smol-timeout/blob/main/LICENSE.txt][https://img.shields.io/crates/l/smol-timeout.svg]]
[[https://crates.io/crates/smol-timeout][https://img.shields.io/crates/v/smol-timeout.svg]]
[[https://docs.rs/smol-timeout][https://docs.rs/smol-timeout/badge.svg]]
A way to poll a future until it or a timer completes.
** Example
#+BEGIN_SRC rust
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));
#+END_SRC
** License
#+BEGIN_QUOTE
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/.
#+END_QUOTE
|