add tokio timer
This commit is contained in:
parent
b8f3034014
commit
7cb25a7743
2 changed files with 57 additions and 1 deletions
|
|
@ -4,13 +4,14 @@ mod executor;
|
||||||
mod tokio_timer;
|
mod tokio_timer;
|
||||||
mod watch;
|
mod watch;
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(crate) mod rt {
|
pub(crate) mod rt {
|
||||||
pub(crate) use super::executor::LocalExecutor;
|
pub(crate) use super::executor::LocalExecutor;
|
||||||
pub(crate) use super::tokio_timer::{TokioSleep, TokioTimer};
|
pub(crate) use super::tokio_timer::{TokioSleep, TokioTimer};
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub(crate) mod body {
|
pub(crate) mod body {
|
||||||
pub(crate) use super::body_incoming_like::IncomingLike;
|
pub(crate) use super::body_incoming_like::IncomingLike;
|
||||||
#[allow(unused)]
|
|
||||||
pub(crate) use super::body_type::{
|
pub(crate) use super::body_type::{
|
||||||
empty, full, wrap_incoming_body_response, wrap_synthetic_body_response, BoxBody, IncomingOr,
|
empty, full, wrap_incoming_body_response, wrap_synthetic_body_response, BoxBody, IncomingOr,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
55
rpxy-lib/src/hyper_ext/tokio_timer.rs
Normal file
55
rpxy-lib/src/hyper_ext/tokio_timer.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
use std::{
|
||||||
|
future::Future,
|
||||||
|
pin::Pin,
|
||||||
|
task::{Context, Poll},
|
||||||
|
time::{Duration, Instant},
|
||||||
|
};
|
||||||
|
|
||||||
|
use hyper::rt::{Sleep, Timer};
|
||||||
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct TokioTimer;
|
||||||
|
|
||||||
|
impl Timer for TokioTimer {
|
||||||
|
fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> {
|
||||||
|
Box::pin(TokioSleep {
|
||||||
|
inner: tokio::time::sleep(duration),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> {
|
||||||
|
Box::pin(TokioSleep {
|
||||||
|
inner: tokio::time::sleep_until(deadline.into()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
|
||||||
|
if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<TokioSleep>() {
|
||||||
|
sleep.reset(new_deadline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pin_project! {
|
||||||
|
pub(crate) struct TokioSleep {
|
||||||
|
#[pin]
|
||||||
|
pub(crate) inner: tokio::time::Sleep,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Future for TokioSleep {
|
||||||
|
type Output = ();
|
||||||
|
|
||||||
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
|
self.project().inner.poll(cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sleep for TokioSleep {}
|
||||||
|
|
||||||
|
impl TokioSleep {
|
||||||
|
pub fn reset(self: Pin<&mut Self>, deadline: Instant) {
|
||||||
|
self.project().inner.as_mut().reset(deadline.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue