1 | #![allow (dead_code)] |
2 | |
3 | use std::fmt; |
4 | use std::pin::Pin; |
5 | use std::sync::Arc; |
6 | use std::time::Duration; |
7 | use std::time::Instant; |
8 | |
9 | use hyper::rt::Sleep; |
10 | |
11 | #[derive (Clone)] |
12 | pub(crate) struct Timer(Arc<dyn hyper::rt::Timer + Send + Sync>); |
13 | |
14 | // =====impl Timer===== |
15 | impl Timer { |
16 | pub(crate) fn new<T>(inner: T) -> Self |
17 | where |
18 | T: hyper::rt::Timer + Send + Sync + 'static, |
19 | { |
20 | Self(Arc::new(data:inner)) |
21 | } |
22 | } |
23 | |
24 | impl fmt::Debug for Timer { |
25 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
26 | f.debug_struct(name:"Timer" ).finish() |
27 | } |
28 | } |
29 | |
30 | impl hyper::rt::Timer for Timer { |
31 | fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> { |
32 | self.0.sleep(duration) |
33 | } |
34 | |
35 | fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> { |
36 | self.0.sleep_until(deadline) |
37 | } |
38 | } |
39 | |