From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2775767672 for ; Tue, 12 Jan 2021 14:59:06 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1586A26A76 for ; Tue, 12 Jan 2021 14:58:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 7A87226A2A for ; Tue, 12 Jan 2021 14:58:35 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 430AF45637 for ; Tue, 12 Jan 2021 14:58:35 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Tue, 12 Jan 2021 14:58:14 +0100 Message-Id: <20210112135830.2798301-5-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210112135830.2798301-1-f.gruenbichler@proxmox.com> References: <20210112135830.2798301-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [future.rs, mod.rs] Subject: [pbs-devel] [PATCH proxmox 4/4] tokio 1.0: drop TimeoutFutureExt X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jan 2021 13:59:06 -0000 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 --- 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 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> + 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` 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> + Unpin + Send + 'a> - where - Self: Sized + Unpin + Send + 'a, - Self::Output: Into>, - E: Into + 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