1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-19 08:24:41 +01:00

Check service readiness for new_apply_cfg combinator

This commit is contained in:
Nikolay Kim 2019-08-27 05:28:15 +06:00
parent aad013f559
commit 1a644c6bb1
3 changed files with 28 additions and 7 deletions

View File

@ -1,5 +1,12 @@
# Changes # Changes
## [0.4.2] - 2019-08-27
### Fixed
* Check service readiness for `new_apply_cfg` combinator
## [0.4.1] - 2019-06-06 ## [0.4.1] - 2019-06-06
### Added ### Added

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-service" name = "actix-service"
version = "0.4.1" version = "0.4.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix Service" description = "Actix Service"
keywords = ["network", "framework", "async", "futures"] keywords = ["network", "framework", "async", "futures"]

View File

@ -49,6 +49,7 @@ where
C: Clone, C: Clone,
F: FnMut(&C, &mut T::Service) -> R, F: FnMut(&C, &mut T::Service) -> R,
T: NewService<Config = ()>, T: NewService<Config = ()>,
T::InitError: From<T::Error>,
R: IntoFuture<Error = T::InitError>, R: IntoFuture<Error = T::InitError>,
R::Item: IntoService<S>, R::Item: IntoService<S>,
S: Service, S: Service,
@ -179,6 +180,7 @@ where
C: Clone, C: Clone,
F: FnMut(&C, &mut T::Service) -> R, F: FnMut(&C, &mut T::Service) -> R,
T: NewService<Config = ()>, T: NewService<Config = ()>,
T::InitError: From<T::Error>,
R: IntoFuture<Error = T::InitError>, R: IntoFuture<Error = T::InitError>,
R::Item: IntoService<S>, R::Item: IntoService<S>,
S: Service, S: Service,
@ -196,8 +198,9 @@ where
ApplyConfigNewServiceFut { ApplyConfigNewServiceFut {
f: self.f.clone(), f: self.f.clone(),
cfg: cfg.clone(), cfg: cfg.clone(),
srv: Some(self.srv.get_ref().new_service(&())),
fut: None, fut: None,
srv: None,
srv_fut: Some(self.srv.get_ref().new_service(&())),
_t: PhantomData, _t: PhantomData,
} }
} }
@ -208,13 +211,15 @@ where
C: Clone, C: Clone,
F: FnMut(&C, &mut T::Service) -> R, F: FnMut(&C, &mut T::Service) -> R,
T: NewService<Config = ()>, T: NewService<Config = ()>,
T::InitError: From<T::Error>,
R: IntoFuture<Error = T::InitError>, R: IntoFuture<Error = T::InitError>,
R::Item: IntoService<S>, R::Item: IntoService<S>,
S: Service, S: Service,
{ {
cfg: C, cfg: C,
f: Cell<F>, f: Cell<F>,
srv: Option<T::Future>, srv: Option<T::Service>,
srv_fut: Option<T::Future>,
fut: Option<R::Future>, fut: Option<R::Future>,
_t: PhantomData<(S,)>, _t: PhantomData<(S,)>,
} }
@ -224,6 +229,7 @@ where
C: Clone, C: Clone,
F: FnMut(&C, &mut T::Service) -> R, F: FnMut(&C, &mut T::Service) -> R,
T: NewService<Config = ()>, T: NewService<Config = ()>,
T::InitError: From<T::Error>,
R: IntoFuture<Error = T::InitError>, R: IntoFuture<Error = T::InitError>,
R::Item: IntoService<S>, R::Item: IntoService<S>,
S: Service, S: Service,
@ -232,12 +238,12 @@ where
type Error = R::Error; type Error = R::Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> { fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
if let Some(ref mut fut) = self.srv { if let Some(ref mut fut) = self.srv_fut {
match fut.poll()? { match fut.poll()? {
Async::NotReady => return Ok(Async::NotReady), Async::NotReady => return Ok(Async::NotReady),
Async::Ready(mut srv) => { Async::Ready(srv) => {
let _ = self.srv.take(); let _ = self.srv_fut.take();
self.fut = Some(self.f.get_mut()(&self.cfg, &mut srv).into_future()); self.srv = Some(srv);
return self.poll(); return self.poll();
} }
} }
@ -245,6 +251,14 @@ where
if let Some(ref mut fut) = self.fut { if let Some(ref mut fut) = self.fut {
Ok(Async::Ready(try_ready!(fut.poll()).into_service())) Ok(Async::Ready(try_ready!(fut.poll()).into_service()))
} else if let Some(ref mut srv) = self.srv {
match srv.poll_ready()? {
Async::NotReady => Ok(Async::NotReady),
Async::Ready(_) => {
self.fut = Some(self.f.get_mut()(&self.cfg, srv).into_future());
return self.poll();
}
}
} else { } else {
Ok(Async::NotReady) Ok(Async::NotReady)
} }