From 18db42cd2cb892432fd7896f0da7e9d19221214b Mon Sep 17 00:00:00 2001 From: Wladimir Palant <374261+palant@users.noreply.github.com> Date: Fri, 28 Jun 2024 21:02:29 +0000 Subject: Fixes #311 - Make timeouts Sync Includes-commit: 3faed99e264cda6ba3986912d06c6e67bf5df13b Replicated-from: https://github.com/cloudflare/pingora/pull/312 --- .bleep | 2 +- pingora-timeout/Cargo.toml | 1 - pingora-timeout/src/fast_timeout.rs | 2 +- pingora-timeout/src/lib.rs | 7 +++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.bleep b/.bleep index c59abc6..3343758 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -819e3bc852ba912c6fcf02bc9aa4f2c5d6a61d79 +a0543ca77c1d82a93f88fdf93f7a0e8e344f03d3 \ No newline at end of file diff --git a/pingora-timeout/Cargo.toml b/pingora-timeout/Cargo.toml index 92e72e7..1bca525 100644 --- a/pingora-timeout/Cargo.toml +++ b/pingora-timeout/Cargo.toml @@ -24,7 +24,6 @@ tokio = { workspace = true, features = [ "sync", ] } pin-project-lite = "0.2" -futures = "0.3" once_cell = { workspace = true } parking_lot = "0.12" thread_local = "1.0" diff --git a/pingora-timeout/src/fast_timeout.rs b/pingora-timeout/src/fast_timeout.rs index c3b251a..d5de5f4 100644 --- a/pingora-timeout/src/fast_timeout.rs +++ b/pingora-timeout/src/fast_timeout.rs @@ -50,7 +50,7 @@ fn check_clock_thread(tm: &Arc) { pub struct FastTimeout(Duration); impl ToTimeout for FastTimeout { - fn timeout(&self) -> BoxFuture<'static, ()> { + fn timeout(&self) -> Pin + Send + Sync>> { Box::pin(TIMER_MANAGER.register_timer(self.0).poll()) } diff --git a/pingora-timeout/src/lib.rs b/pingora-timeout/src/lib.rs index 75b0663..26bb5b9 100644 --- a/pingora-timeout/src/lib.rs +++ b/pingora-timeout/src/lib.rs @@ -39,7 +39,6 @@ pub mod timer; pub use fast_timeout::fast_sleep as sleep; pub use fast_timeout::fast_timeout as timeout; -use futures::future::BoxFuture; use pin_project_lite::pin_project; use std::future::Future; use std::pin::Pin; @@ -50,7 +49,7 @@ use tokio::time::{sleep as tokio_sleep, Duration}; /// /// Users don't need to interact with this trait pub trait ToTimeout { - fn timeout(&self) -> BoxFuture<'static, ()>; + fn timeout(&self) -> Pin + Send + Sync>>; fn create(d: Duration) -> Self; } @@ -60,7 +59,7 @@ pub trait ToTimeout { pub struct TokioTimeout(Duration); impl ToTimeout for TokioTimeout { - fn timeout(&self) -> BoxFuture<'static, ()> { + fn timeout(&self) -> Pin + Send + Sync>> { Box::pin(tokio_sleep(self.0)) } @@ -100,7 +99,7 @@ pin_project! { #[pin] value: T, #[pin] - delay: Option>, + delay: Option + Send + Sync>>>, callback: F, // callback to create the timer } } -- cgit v1.2.3