From 67961f8a36750e2c22f103aa0276f7271c67253d Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 29 Oct 2018 15:48:56 -0700 Subject: [PATCH] rename timer to time --- examples/basic.rs | 3 ++- examples/ssl.rs | 3 ++- src/codec/framed_write.rs | 3 ++- src/keepalive.rs | 26 +++++++++++++------------- src/lib.rs | 7 ++----- src/server/accept.rs | 8 +++++--- src/server/worker.rs | 3 ++- src/{timer.rs => time.rs} | 30 +++++++++++++++--------------- 8 files changed, 43 insertions(+), 40 deletions(-) rename src/{timer.rs => time.rs} (73%) diff --git a/examples/basic.rs b/examples/basic.rs index 8162fcc6..f31b6d76 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -80,7 +80,8 @@ fn main() { future::ok(()) }) }, - ).unwrap() + ) + .unwrap() .start(); sys.run(); diff --git a/examples/ssl.rs b/examples/ssl.rs index 752af4cb..25bc6aad 100644 --- a/examples/ssl.rs +++ b/examples/ssl.rs @@ -60,7 +60,8 @@ fn main() { println!("got ssl connection {:?}", num); future::ok(()) }) - }).unwrap() + }) + .unwrap() .start(); sys.run(); diff --git a/src/codec/framed_write.rs b/src/codec/framed_write.rs index 1348b09c..a39f6d03 100644 --- a/src/codec/framed_write.rs +++ b/src/codec/framed_write.rs @@ -197,7 +197,8 @@ where io::ErrorKind::WriteZero, "failed to \ write frame to transport", - ).into()); + ) + .into()); } // TODO: Add a way to `bytes` to do this w/o returning the drained diff --git a/src/keepalive.rs b/src/keepalive.rs index b79c6f80..39d0998e 100644 --- a/src/keepalive.rs +++ b/src/keepalive.rs @@ -6,13 +6,13 @@ use futures::{Async, Future, Poll}; use tokio_timer::Delay; use super::service::{NewService, Service}; -use super::timer::{LowResTimer, LowResTimerService}; +use super::time::{LowResTime, LowResTimeService}; use super::Never; pub struct KeepAlive { f: F, ka: Duration, - timer: LowResTimer, + time: LowResTime, _t: PhantomData<(R, E)>, } @@ -20,11 +20,11 @@ impl KeepAlive where F: Fn() -> E + Clone, { - pub fn new(ka: Duration, timer: LowResTimer, f: F) -> Self { + pub fn new(ka: Duration, time: LowResTime, f: F) -> Self { KeepAlive { f, ka, - timer, + time, _t: PhantomData, } } @@ -38,7 +38,7 @@ where KeepAlive { f: self.f.clone(), ka: self.ka, - timer: self.timer.clone(), + time: self.time.clone(), _t: PhantomData, } } @@ -58,7 +58,7 @@ where fn new_service(&self) -> Self::Future { ok(KeepAliveService::new( self.ka, - self.timer.timer(), + self.time.timer(), self.f.clone(), )) } @@ -67,7 +67,7 @@ where pub struct KeepAliveService { f: F, ka: Duration, - timer: LowResTimerService, + time: LowResTimeService, delay: Delay, expire: Instant, _t: PhantomData<(R, E)>, @@ -77,14 +77,14 @@ impl KeepAliveService where F: Fn() -> E, { - pub fn new(ka: Duration, timer: LowResTimerService, f: F) -> Self { - let expire = timer.now() + ka; + pub fn new(ka: Duration, time: LowResTimeService, f: F) -> Self { + let expire = time.now() + ka; KeepAliveService { f, ka, - timer, - delay: Delay::new(expire), + time, expire, + delay: Delay::new(expire), _t: PhantomData, } } @@ -102,7 +102,7 @@ where fn poll_ready(&mut self) -> Poll<(), Self::Error> { match self.delay.poll() { Ok(Async::Ready(_)) => { - let now = self.timer.now(); + let now = self.time.now(); if self.expire <= now { Err((self.f)()) } else { @@ -117,7 +117,7 @@ where } fn call(&mut self, req: Self::Request) -> Self::Future { - self.expire = self.timer.now() + self.ka; + self.expire = self.time.now() + self.ka; ok(req) } } diff --git a/src/lib.rs b/src/lib.rs index a50debd2..4240d062 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,10 +9,7 @@ #![cfg_attr( feature = "cargo-clippy", - allow( - declare_interior_mutable_const, - borrow_interior_mutable_const - ) + allow(declare_interior_mutable_const, borrow_interior_mutable_const) )] #[macro_use] @@ -69,8 +66,8 @@ pub mod server; pub mod service; pub mod ssl; pub mod stream; +pub mod time; pub mod timeout; -pub mod timer; #[derive(Copy, Clone, Debug)] pub enum Never {} diff --git a/src/server/accept.rs b/src/server/accept.rs index 09b1f16f..9135b1f6 100644 --- a/src/server/accept.rs +++ b/src/server/accept.rs @@ -243,9 +243,11 @@ impl Accept { for event in events.iter() { let token = event.token(); match token { - CMD => if !self.process_cmd() { - return; - }, + CMD => { + if !self.process_cmd() { + return; + } + } TIMER => self.process_timer(), NOTIFY => self.backpressure(false), _ => { diff --git a/src/server/worker.rs b/src/server/worker.rs index a89cf31b..ae8ee333 100644 --- a/src/server/worker.rs +++ b/src/server/worker.rs @@ -151,7 +151,8 @@ impl Worker { .map_err(|e| { error!("Can not start worker: {:?}", e); Arbiter::current().do_send(StopArbiter(0)); - }).and_then(move |services| { + }) + .and_then(move |services| { wrk.services.extend(services); wrk }), diff --git a/src/timer.rs b/src/time.rs similarity index 73% rename from src/timer.rs rename to src/time.rs index 7b58db00..330aacae 100644 --- a/src/timer.rs +++ b/src/time.rs @@ -10,7 +10,7 @@ use super::service::{NewService, Service}; use super::Never; #[derive(Clone, Debug)] -pub struct LowResTimer(Cell); +pub struct LowResTime(Cell); #[derive(Debug)] struct Inner { @@ -27,28 +27,28 @@ impl Inner { } } -impl LowResTimer { - pub fn with(resolution: Duration) -> LowResTimer { - LowResTimer(Cell::new(Inner::new(resolution))) +impl LowResTime { + pub fn with(resolution: Duration) -> LowResTime { + LowResTime(Cell::new(Inner::new(resolution))) } - pub fn timer(&self) -> LowResTimerService { - LowResTimerService(self.0.clone()) + pub fn timer(&self) -> LowResTimeService { + LowResTimeService(self.0.clone()) } } -impl Default for LowResTimer { +impl Default for LowResTime { fn default() -> Self { - LowResTimer(Cell::new(Inner::new(Duration::from_secs(1)))) + LowResTime(Cell::new(Inner::new(Duration::from_secs(1)))) } } -impl NewService for LowResTimer { +impl NewService for LowResTime { type Request = (); type Response = Instant; type Error = Never; type InitError = Never; - type Service = LowResTimerService; + type Service = LowResTimeService; type Future = FutureResult; fn new_service(&self) -> Self::Future { @@ -57,11 +57,11 @@ impl NewService for LowResTimer { } #[derive(Clone, Debug)] -pub struct LowResTimerService(Cell); +pub struct LowResTimeService(Cell); -impl LowResTimerService { - pub fn with(resolution: Duration) -> LowResTimerService { - LowResTimerService(Cell::new(Inner::new(resolution))) +impl LowResTimeService { + pub fn with(resolution: Duration) -> LowResTimeService { + LowResTimeService(Cell::new(Inner::new(resolution))) } /// Get current time. This function has to be called from @@ -88,7 +88,7 @@ impl LowResTimerService { } } -impl Service for LowResTimerService { +impl Service for LowResTimeService { type Request = (); type Response = Instant; type Error = Never;