From 1a644c6bb1e3710d7976b4a54fdca07e4c4af6c6 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 27 Aug 2019 05:28:15 +0600 Subject: [PATCH] Check service readiness for new_apply_cfg combinator --- actix-service/CHANGES.md | 7 +++++++ actix-service/Cargo.toml | 2 +- actix-service/src/apply_cfg.rs | 26 ++++++++++++++++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/actix-service/CHANGES.md b/actix-service/CHANGES.md index 047de4e3..859491b4 100644 --- a/actix-service/CHANGES.md +++ b/actix-service/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.4.2] - 2019-08-27 + +### Fixed + +* Check service readiness for `new_apply_cfg` combinator + + ## [0.4.1] - 2019-06-06 ### Added diff --git a/actix-service/Cargo.toml b/actix-service/Cargo.toml index 7425902a..8bdf6bcf 100644 --- a/actix-service/Cargo.toml +++ b/actix-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-service" -version = "0.4.1" +version = "0.4.2" authors = ["Nikolay Kim "] description = "Actix Service" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-service/src/apply_cfg.rs b/actix-service/src/apply_cfg.rs index 66137eee..a63de936 100644 --- a/actix-service/src/apply_cfg.rs +++ b/actix-service/src/apply_cfg.rs @@ -49,6 +49,7 @@ where C: Clone, F: FnMut(&C, &mut T::Service) -> R, T: NewService, + T::InitError: From, R: IntoFuture, R::Item: IntoService, S: Service, @@ -179,6 +180,7 @@ where C: Clone, F: FnMut(&C, &mut T::Service) -> R, T: NewService, + T::InitError: From, R: IntoFuture, R::Item: IntoService, S: Service, @@ -196,8 +198,9 @@ where ApplyConfigNewServiceFut { f: self.f.clone(), cfg: cfg.clone(), - srv: Some(self.srv.get_ref().new_service(&())), fut: None, + srv: None, + srv_fut: Some(self.srv.get_ref().new_service(&())), _t: PhantomData, } } @@ -208,13 +211,15 @@ where C: Clone, F: FnMut(&C, &mut T::Service) -> R, T: NewService, + T::InitError: From, R: IntoFuture, R::Item: IntoService, S: Service, { cfg: C, f: Cell, - srv: Option, + srv: Option, + srv_fut: Option, fut: Option, _t: PhantomData<(S,)>, } @@ -224,6 +229,7 @@ where C: Clone, F: FnMut(&C, &mut T::Service) -> R, T: NewService, + T::InitError: From, R: IntoFuture, R::Item: IntoService, S: Service, @@ -232,12 +238,12 @@ where type Error = R::Error; fn poll(&mut self) -> Poll { - if let Some(ref mut fut) = self.srv { + if let Some(ref mut fut) = self.srv_fut { match fut.poll()? { Async::NotReady => return Ok(Async::NotReady), - Async::Ready(mut srv) => { - let _ = self.srv.take(); - self.fut = Some(self.f.get_mut()(&self.cfg, &mut srv).into_future()); + Async::Ready(srv) => { + let _ = self.srv_fut.take(); + self.srv = Some(srv); return self.poll(); } } @@ -245,6 +251,14 @@ where if let Some(ref mut fut) = self.fut { 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 { Ok(Async::NotReady) }