Skip to content

Commit

Permalink
Check ready state for map_config_service
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Apr 27, 2020
1 parent db80e15 commit a4e4adb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ntex-service/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion ntex-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
16 changes: 12 additions & 4 deletions ntex-service/src/map_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
}
Expand All @@ -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) => {
Expand Down

0 comments on commit a4e4adb

Please sign in to comment.