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

Release future early for .and_then() and .then() combinators

This commit is contained in:
Nikolay Kim 2018-12-12 18:00:35 -08:00
parent e8a1664c15
commit 61939c7af2
4 changed files with 19 additions and 9 deletions

View File

@ -1,5 +1,12 @@
# Changes # Changes
## [0.1.2] - 2018-12-12
### Fixed
* Release future early for `.and_then()` and `.then()` combinators
## [0.1.1] - 2018-12-09 ## [0.1.1] - 2018-12-09
### Added ### Added

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-service" name = "actix-service"
version = "0.1.1" version = "0.1.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

@ -61,7 +61,7 @@ where
{ {
b: Cell<B>, b: Cell<B>,
fut_b: Option<B::Future>, fut_b: Option<B::Future>,
fut_a: A::Future, fut_a: Option<A::Future>,
} }
impl<A, B, Request> AndThenFuture<A, B, Request> impl<A, B, Request> AndThenFuture<A, B, Request>
@ -69,10 +69,10 @@ where
A: Service<Request>, A: Service<Request>,
B: Service<A::Response, Error = A::Error>, B: Service<A::Response, Error = A::Error>,
{ {
fn new(fut_a: A::Future, b: Cell<B>) -> Self { fn new(a: A::Future, b: Cell<B>) -> Self {
AndThenFuture { AndThenFuture {
b, b,
fut_a, fut_a: Some(a),
fut_b: None, fut_b: None,
} }
} }
@ -91,8 +91,9 @@ where
return fut.poll(); return fut.poll();
} }
match self.fut_a.poll() { match self.fut_a.as_mut().expect("Bug in actix-service").poll() {
Ok(Async::Ready(resp)) => { Ok(Async::Ready(resp)) => {
let _ = self.fut_a.take();
self.fut_b = Some(self.b.get_mut().call(resp)); self.fut_b = Some(self.b.get_mut().call(resp));
self.poll() self.poll()
} }

View File

@ -61,7 +61,7 @@ where
{ {
b: Cell<B>, b: Cell<B>,
fut_b: Option<B::Future>, fut_b: Option<B::Future>,
fut_a: A::Future, fut_a: Option<A::Future>,
} }
impl<A, B, Request> ThenFuture<A, B, Request> impl<A, B, Request> ThenFuture<A, B, Request>
@ -69,10 +69,10 @@ where
A: Service<Request>, A: Service<Request>,
B: Service<Result<A::Response, A::Error>>, B: Service<Result<A::Response, A::Error>>,
{ {
fn new(fut_a: A::Future, b: Cell<B>) -> Self { fn new(a: A::Future, b: Cell<B>) -> Self {
ThenFuture { ThenFuture {
b, b,
fut_a, fut_a: Some(a),
fut_b: None, fut_b: None,
} }
} }
@ -91,12 +91,14 @@ where
return fut.poll(); return fut.poll();
} }
match self.fut_a.poll() { match self.fut_a.as_mut().expect("bug in actix-service").poll() {
Ok(Async::Ready(resp)) => { Ok(Async::Ready(resp)) => {
let _ = self.fut_a.take();
self.fut_b = Some(self.b.get_mut().call(Ok(resp))); self.fut_b = Some(self.b.get_mut().call(Ok(resp)));
self.poll() self.poll()
} }
Err(err) => { Err(err) => {
let _ = self.fut_a.take();
self.fut_b = Some(self.b.get_mut().call(Err(err))); self.fut_b = Some(self.b.get_mut().call(Err(err)));
self.poll() self.poll()
} }