mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 13:27:39 +03:00
Check ready state for map_config_service
This commit is contained in:
parent
db80e1556f
commit
a4e4adb63a
3 changed files with 17 additions and 5 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [0.1.2] - 2020-04-27
|
||||
|
||||
* Check ready state for map_config_service
|
||||
|
||||
## [0.1.1] - 2020-04-22
|
||||
|
||||
* Add `map_config_service`, replacement for `apply_cfg`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-service"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "ntex service"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
|
|
|
@ -214,11 +214,11 @@ where
|
|||
|
||||
fn new_service(&self, cfg: C) -> Self::Future {
|
||||
let inner = self.0.clone();
|
||||
if let Some(ref mapper) = *self.0.mapper.borrow() {
|
||||
if self.0.mapper.borrow().is_some() {
|
||||
MapConfigServiceResponse {
|
||||
inner,
|
||||
config: None,
|
||||
state: ResponseState::MapConfig(mapper.call(cfg)),
|
||||
config: Some(cfg),
|
||||
state: ResponseState::MapReady,
|
||||
}
|
||||
} else {
|
||||
MapConfigServiceResponse {
|
||||
|
@ -245,6 +245,7 @@ where
|
|||
#[pin_project::pin_project]
|
||||
enum ResponseState<A: ServiceFactory, M: ServiceFactory> {
|
||||
CreateMapper(#[pin] M::Future),
|
||||
MapReady,
|
||||
MapConfig(#[pin] <M::Service as Service>::Future),
|
||||
CreateService(#[pin] A::Future),
|
||||
}
|
||||
|
@ -270,9 +271,16 @@ where
|
|||
match this.state.as_mut().project() {
|
||||
ResponseState::CreateMapper(fut) => {
|
||||
let mapper = ready!(fut.poll(cx))?;
|
||||
let fut = mapper.call(this.config.take().unwrap());
|
||||
*this.inner.mapper.borrow_mut() = Some(mapper);
|
||||
this.state.set(ResponseState::MapReady);
|
||||
self.poll(cx)
|
||||
}
|
||||
ResponseState::MapReady => {
|
||||
let mapper = this.inner.mapper.borrow();
|
||||
ready!(mapper.as_ref().unwrap().poll_ready(cx))?;
|
||||
let fut = mapper.as_ref().unwrap().call(this.config.take().unwrap());
|
||||
this.state.set(ResponseState::MapConfig(fut));
|
||||
drop(mapper);
|
||||
self.poll(cx)
|
||||
}
|
||||
ResponseState::MapConfig(fut) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue