async_tftp/utils.rs
1use async_io::Timer;
2use futures_lite::future;
3use std::future::Future;
4use std::io;
5use std::time::Duration;
6
7pub async fn io_timeout<T>(
8 dur: Duration,
9 f: impl Future<Output = io::Result<T>>,
10) -> io::Result<T> {
11 future::race(f, async move {
12 Timer::after(dur).await;
13 Err(io::ErrorKind::TimedOut.into())
14 })
15 .await
16}