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::{
|
use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
|
future::Future,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "gemini_srv")]
|
#[cfg(feature = "gemini_srv")]
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
@ -99,6 +100,7 @@ use tokio::{
|
||||||
io::BufReader,
|
io::BufReader,
|
||||||
net::TcpListener,
|
net::TcpListener,
|
||||||
net::ToSocketAddrs,
|
net::ToSocketAddrs,
|
||||||
|
time,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "scgi_srv")]
|
#[cfg(feature = "scgi_srv")]
|
||||||
|
@ -111,7 +113,6 @@ use tokio::{
|
||||||
#[cfg(feature = "ratelimiting")]
|
#[cfg(feature = "ratelimiting")]
|
||||||
use tokio::time::interval;
|
use tokio::time::interval;
|
||||||
use anyhow::*;
|
use anyhow::*;
|
||||||
use crate::util::opt_timeout;
|
|
||||||
use routing::RoutingNode;
|
use routing::RoutingNode;
|
||||||
#[cfg(feature = "ratelimiting")]
|
#[cfg(feature = "ratelimiting")]
|
||||||
use ratelimiting::RateLimiter;
|
use ratelimiting::RateLimiter;
|
||||||
|
@ -832,3 +833,10 @@ async fn prune_ratelimit_log(rate_limits: Arc<RoutingNode<RateLimiter<IpAddr>>>)
|
||||||
|
|
||||||
#[cfg(feature = "ratelimiting")]
|
#[cfg(feature = "ratelimiting")]
|
||||||
enum Never {}
|
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>,
|
C: AsRef<T> + Into<T::Owned>,
|
||||||
T: ToOwned + ?Sized,
|
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