[pbs-devel] [PATCH proxmox 4/4] tokio 1.0: drop TimeoutFutureExt

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Jan 12 14:58:14 CET 2021


tokio's Sleep/Delay/Timeout are no longer Unpin, complicating this
wrapper. we can just use tokio::time::timeout directly as needed..

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 proxmox/src/tools/future.rs | 48 -------------------------------------
 proxmox/src/tools/mod.rs    |  1 -
 2 files changed, 49 deletions(-)
 delete mode 100644 proxmox/src/tools/future.rs

diff --git a/proxmox/src/tools/future.rs b/proxmox/src/tools/future.rs
deleted file mode 100644
index cf9fae7..0000000
--- a/proxmox/src/tools/future.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-//! Common extensions for Futures
-use anyhow::Error;
-use futures::future::{select, Either, FutureExt};
-use std::future::Future;
-use std::time::Duration;
-use tokio::time::delay_for;
-
-impl<T> TimeoutFutureExt for T where T: Future {}
-
-/// Implements a timeout for futures, automatically aborting them if the timeout runs out before
-/// the base future completes.
-pub trait TimeoutFutureExt: Future {
-    /// Returned Future returns 'None' in case the timeout was reached, otherwise the original
-    /// return value.
-    fn or_timeout<'a>(
-        self,
-        timeout: Duration,
-    ) -> Box<dyn Future<Output = Option<Self::Output>> + Unpin + Send + 'a>
-    where
-        Self: Sized + Unpin + Send + 'a,
-    {
-        let timeout_fut = delay_for(timeout);
-        Box::new(select(self, timeout_fut).map(|res| match res {
-            Either::Left((result, _)) => Some(result),
-            Either::Right(((), _)) => None,
-        }))
-    }
-
-    /// Returned Future returns either the original result, or `Err<err>` in case the timeout is
-    /// reached. Basically a shorthand to flatten a future that returns a `Result<_, Error>` with a
-    /// timeout. The base Future can return any kind of Error that can be made into an
-    /// `anyhow::Error`.
-    fn or_timeout_err<'a, O, E>(
-        self,
-        timeout: Duration,
-        err: Error,
-    ) -> Box<dyn Future<Output = Result<O, Error>> + Unpin + Send + 'a>
-    where
-        Self: Sized + Unpin + Send + 'a,
-        Self::Output: Into<Result<O, E>>,
-        E: Into<Error> + std::error::Error + Send + Sync + 'static,
-    {
-        Box::new(self.or_timeout(timeout).map(|res| match res {
-            Some(res) => res.into().map_err(Error::from),
-            None => Err(err),
-        }))
-    }
-}
diff --git a/proxmox/src/tools/mod.rs b/proxmox/src/tools/mod.rs
index 5d1f46e..ff3a720 100644
--- a/proxmox/src/tools/mod.rs
+++ b/proxmox/src/tools/mod.rs
@@ -20,7 +20,6 @@ pub mod serde;
 pub mod time;
 pub mod uuid;
 pub mod vec;
-pub mod future;
 
 #[cfg(feature = "websocket")]
 pub mod websocket;
-- 
2.20.1






More information about the pbs-devel mailing list