#[cfg(any(
feature = "tcp",
feature = "udp",
feature = "dns",
feature = "http",
feature = "ws",
feature = "mqtt",
feature = "hls",
))]
use std::io::{self, Result};
#[cfg(any(
feature = "tcp",
feature = "udp",
feature = "dns",
feature = "http",
feature = "ws",
feature = "mqtt",
feature = "hls",
))]
use std::time::Duration;
#[cfg(any(
feature = "tcp",
feature = "udp",
feature = "dns",
feature = "http",
feature = "ws",
feature = "mqtt",
feature = "hls",
))]
use tokio::time::timeout;
#[cfg(any(
feature = "tcp",
feature = "udp",
feature = "dns",
feature = "http",
feature = "ws",
feature = "mqtt",
feature = "hls",
))]
pub(crate) async fn with_timeout<F>(d: Duration, fut: F) -> Result<()>
where
F: std::future::Future<Output = Result<()>>,
{
match timeout(d, fut).await {
Ok(inner) => inner,
Err(_) => Err(io::Error::new(
io::ErrorKind::TimedOut,
"operation timed out",
)),
}
}