Move opt_timeout to lib.rs
This commit is contained in:
parent
cb9b3ea167
commit
f592ecf73b
10
src/lib.rs
10
src/lib.rs
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue