-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add timer support for
legacy::Pool
(#84)
- Loading branch information
Showing
4 changed files
with
122 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#![allow(dead_code)] | ||
|
||
use std::fmt; | ||
use std::pin::Pin; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use std::time::Instant; | ||
|
||
use hyper::rt::Sleep; | ||
|
||
#[derive(Clone)] | ||
pub(crate) struct Timer(Arc<dyn hyper::rt::Timer + Send + Sync>); | ||
|
||
// =====impl Timer===== | ||
impl Timer { | ||
pub(crate) fn new<T>(inner: T) -> Self | ||
where | ||
T: hyper::rt::Timer + Send + Sync + 'static, | ||
{ | ||
Self(Arc::new(inner)) | ||
} | ||
} | ||
|
||
impl fmt::Debug for Timer { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_struct("Timer").finish() | ||
} | ||
} | ||
|
||
impl hyper::rt::Timer for Timer { | ||
fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> { | ||
self.0.sleep(duration) | ||
} | ||
|
||
fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> { | ||
self.0.sleep_until(deadline) | ||
} | ||
} |