From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 4/4] tokio 1.0: drop TimeoutFutureExt
Date: Tue, 12 Jan 2021 14:58:14 +0100 [thread overview]
Message-ID: <20210112135830.2798301-5-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20210112135830.2798301-1-f.gruenbichler@proxmox.com>
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@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
next prev parent reply other threads:[~2021-01-12 13:59 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 13:58 [pbs-devel] [PATCH-SERIES 0/20] update to tokio 1.0 and friends Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 1/4] Cargo.toml: update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 2/4] update to rustyline 7 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 3/4] update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` Fabian Grünbichler [this message]
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 01/12] " Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 02/12] tokio 1.0: delay -> sleep Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 03/12] proxmox XXX: use tokio::time::timeout directly Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 04/12] tokio 1.0: AsyncRead/Seek with ReadBuf Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 05/12] tokio: adapt to 1.0 runtime changes Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 06/12] tokio: adapt to 1.0 process:Child changes Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 07/12] tokio 1.0: use ReceiverStream from tokio-stream Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 08/12] tokio 1.0: update to new tokio-openssl interface Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 09/12] tokio 1.0: update to new Signal interface Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 10/12] hyper: use new hyper::upgrade Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 11/12] examples: unify h2 examples Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 12/12] cleanup: remove unnecessary 'mut' and '.clone()' Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-fuse] update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH pxar 1/3] " Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [RFC pxar 2/3] clippy: use matches! instead of match Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [RFC pxar 3/3] remove futures-io feature Fabian Grünbichler
2021-01-12 14:42 ` Wolfgang Bumiller
2021-01-12 14:52 ` [pbs-devel] [PATCH-SERIES 0/20] update to tokio 1.0 and friends Wolfgang Bumiller
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox 1/3] fix u2f example Fabian Grünbichler
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox-backup] proxmox XXX: adapt to moved ParameterSchema Fabian Grünbichler
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox 2/3] move ParameterSchema from router to schema Fabian Grünbichler
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox 3/3] build: add autopkgtest target Fabian Grünbichler
2021-01-14 13:41 ` [pbs-devel] [PATCH pxar 1/2] fix example Fabian Grünbichler
2021-01-14 13:41 ` [pbs-devel] [PATCH pxar 2/2] build: fix --no-default-features Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210112135830.2798301-5-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox