Move opt_timeout to lib.rs

This commit is contained in:
Emi Tatsuo 2020-12-03 15:04:12 -05:00
parent cb9b3ea167
commit f592ecf73b
Signed by: Emi
GPG key ID: 68FAB2E2E6DFC98B
2 changed files with 9 additions and 8 deletions

View file

@ -81,6 +81,7 @@ compile_error!("Please enable at least one of either the `gemini_srv` or `scgi_s
use std::{
sync::Arc,
time::Duration,
future::Future,
};
#[cfg(feature = "gemini_srv")]
use std::convert::TryFrom;
@ -99,6 +100,7 @@ use tokio::{
io::BufReader,
net::TcpListener,
net::ToSocketAddrs,
time,
prelude::*,
};
#[cfg(feature = "scgi_srv")]
@ -111,7 +113,6 @@ use tokio::{
#[cfg(feature = "ratelimiting")]
use tokio::time::interval;
use anyhow::*;
use crate::util::opt_timeout;
use routing::RoutingNode;
#[cfg(feature = "ratelimiting")]
use ratelimiting::RateLimiter;
@ -832,3 +833,10 @@ async fn prune_ratelimit_log(rate_limits: Arc<RoutingNode<RateLimiter<IpAddr>>>)
#[cfg(feature = "ratelimiting")]
enum Never {}
async fn opt_timeout<T>(duration: Option<time::Duration>, future: impl Future<Output = T>) -> Result<T, time::error::Elapsed> {
match duration {
Some(duration) => time::timeout(duration, future).await,
None => Ok(future.await),
}
}

View file

@ -173,10 +173,3 @@ where
C: AsRef<T> + Into<T::Owned>,
T: ToOwned + ?Sized,
{}
pub(crate) async fn opt_timeout<T>(duration: Option<time::Duration>, future: impl Future<Output = T>) -> Result<T, time::error::Elapsed> {
match duration {
Some(duration) => time::timeout(duration, future).await,
None => Ok(future.await),
}
}