mirror of
https://github.com/cloudflare/pingora.git
synced 2024-09-19 18:21:34 +02:00
Fixes #311 - Make timeouts Sync
Includes-commit: 3faed99e26
Replicated-from: https://github.com/cloudflare/pingora/pull/312
This commit is contained in:
parent
9220e6be2d
commit
18db42cd2c
4 changed files with 5 additions and 7 deletions
2
.bleep
2
.bleep
|
@ -1 +1 @@
|
||||||
819e3bc852ba912c6fcf02bc9aa4f2c5d6a61d79
|
a0543ca77c1d82a93f88fdf93f7a0e8e344f03d3
|
|
@ -24,7 +24,6 @@ tokio = { workspace = true, features = [
|
||||||
"sync",
|
"sync",
|
||||||
] }
|
] }
|
||||||
pin-project-lite = "0.2"
|
pin-project-lite = "0.2"
|
||||||
futures = "0.3"
|
|
||||||
once_cell = { workspace = true }
|
once_cell = { workspace = true }
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
thread_local = "1.0"
|
thread_local = "1.0"
|
||||||
|
|
|
@ -50,7 +50,7 @@ fn check_clock_thread(tm: &Arc<TimerManager>) {
|
||||||
pub struct FastTimeout(Duration);
|
pub struct FastTimeout(Duration);
|
||||||
|
|
||||||
impl ToTimeout for FastTimeout {
|
impl ToTimeout for FastTimeout {
|
||||||
fn timeout(&self) -> BoxFuture<'static, ()> {
|
fn timeout(&self) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> {
|
||||||
Box::pin(TIMER_MANAGER.register_timer(self.0).poll())
|
Box::pin(TIMER_MANAGER.register_timer(self.0).poll())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ pub mod timer;
|
||||||
pub use fast_timeout::fast_sleep as sleep;
|
pub use fast_timeout::fast_sleep as sleep;
|
||||||
pub use fast_timeout::fast_timeout as timeout;
|
pub use fast_timeout::fast_timeout as timeout;
|
||||||
|
|
||||||
use futures::future::BoxFuture;
|
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
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
|
/// Users don't need to interact with this trait
|
||||||
pub trait ToTimeout {
|
pub trait ToTimeout {
|
||||||
fn timeout(&self) -> BoxFuture<'static, ()>;
|
fn timeout(&self) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>>;
|
||||||
fn create(d: Duration) -> Self;
|
fn create(d: Duration) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ pub trait ToTimeout {
|
||||||
pub struct TokioTimeout(Duration);
|
pub struct TokioTimeout(Duration);
|
||||||
|
|
||||||
impl ToTimeout for TokioTimeout {
|
impl ToTimeout for TokioTimeout {
|
||||||
fn timeout(&self) -> BoxFuture<'static, ()> {
|
fn timeout(&self) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> {
|
||||||
Box::pin(tokio_sleep(self.0))
|
Box::pin(tokio_sleep(self.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ pin_project! {
|
||||||
#[pin]
|
#[pin]
|
||||||
value: T,
|
value: T,
|
||||||
#[pin]
|
#[pin]
|
||||||
delay: Option<BoxFuture<'static, ()>>,
|
delay: Option<Pin<Box<dyn Future<Output = ()> + Send + Sync>>>,
|
||||||
callback: F, // callback to create the timer
|
callback: F, // callback to create the timer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue