You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
distant/distant-core/src/client/utils.rs

14 lines
357 B
Rust

use std::{future::Future, time::Duration};
use tokio::{io, time};
// Wraps a future in a tokio timeout call, transforming the error into
// an io error
pub async fn timeout<T, F>(d: Duration, f: F) -> io::Result<T>
where
F: Future<Output = T>,
{
time::timeout(d, f)
.await
.map_err(|x| io::Error::new(io::ErrorKind::TimedOut, x))
}