1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 00:01:11 +01:00

rename timer to time

This commit is contained in:
Nikolay Kim 2018-10-29 15:48:56 -07:00
parent 3d51aa7115
commit 67961f8a36
8 changed files with 43 additions and 40 deletions

View File

@ -80,7 +80,8 @@ fn main() {
future::ok(())
})
},
).unwrap()
)
.unwrap()
.start();
sys.run();

View File

@ -60,7 +60,8 @@ fn main() {
println!("got ssl connection {:?}", num);
future::ok(())
})
}).unwrap()
})
.unwrap()
.start();
sys.run();

View File

@ -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

View File

@ -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<R, E, F> {
f: F,
ka: Duration,
timer: LowResTimer,
time: LowResTime,
_t: PhantomData<(R, E)>,
}
@ -20,11 +20,11 @@ impl<R, E, F> KeepAlive<R, E, F>
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<R, E, F> {
f: F,
ka: Duration,
timer: LowResTimerService,
time: LowResTimeService,
delay: Delay,
expire: Instant,
_t: PhantomData<(R, E)>,
@ -77,14 +77,14 @@ impl<R, E, F> KeepAliveService<R, E, F>
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)
}
}

View File

@ -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 {}

View File

@ -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),
_ => {

View File

@ -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
}),

View File

@ -10,7 +10,7 @@ use super::service::{NewService, Service};
use super::Never;
#[derive(Clone, Debug)]
pub struct LowResTimer(Cell<Inner>);
pub struct LowResTime(Cell<Inner>);
#[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<Self::Service, Self::InitError>;
fn new_service(&self) -> Self::Future {
@ -57,11 +57,11 @@ impl NewService for LowResTimer {
}
#[derive(Clone, Debug)]
pub struct LowResTimerService(Cell<Inner>);
pub struct LowResTimeService(Cell<Inner>);
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;