From 61939c7af2faf1eca46c6ccd5e429ef7a56c738b Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 12 Dec 2018 18:00:35 -0800 Subject: [PATCH] Release future early for .and_then() and .then() combinators --- actix-service/CHANGES.md | 7 +++++++ actix-service/Cargo.toml | 2 +- actix-service/src/and_then.rs | 9 +++++---- actix-service/src/then.rs | 10 ++++++---- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/actix-service/CHANGES.md b/actix-service/CHANGES.md index 81419ee14f..fc8f68cda8 100644 --- a/actix-service/CHANGES.md +++ b/actix-service/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.1.2] - 2018-12-12 + +### Fixed + +* Release future early for `.and_then()` and `.then()` combinators + + ## [0.1.1] - 2018-12-09 ### Added diff --git a/actix-service/Cargo.toml b/actix-service/Cargo.toml index 332d044a29..ca1763ee91 100644 --- a/actix-service/Cargo.toml +++ b/actix-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-service" -version = "0.1.1" +version = "0.1.2" authors = ["Nikolay Kim "] description = "Actix Service" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-service/src/and_then.rs b/actix-service/src/and_then.rs index 1e0649bda8..f9b744689f 100644 --- a/actix-service/src/and_then.rs +++ b/actix-service/src/and_then.rs @@ -61,7 +61,7 @@ where { b: Cell, fut_b: Option, - fut_a: A::Future, + fut_a: Option, } impl AndThenFuture @@ -69,10 +69,10 @@ where A: Service, B: Service, { - fn new(fut_a: A::Future, b: Cell) -> Self { + fn new(a: A::Future, b: Cell) -> Self { AndThenFuture { b, - fut_a, + fut_a: Some(a), fut_b: None, } } @@ -91,8 +91,9 @@ where return fut.poll(); } - match self.fut_a.poll() { + match self.fut_a.as_mut().expect("Bug in actix-service").poll() { Ok(Async::Ready(resp)) => { + let _ = self.fut_a.take(); self.fut_b = Some(self.b.get_mut().call(resp)); self.poll() } diff --git a/actix-service/src/then.rs b/actix-service/src/then.rs index 1cdb62147e..3667553d54 100644 --- a/actix-service/src/then.rs +++ b/actix-service/src/then.rs @@ -61,7 +61,7 @@ where { b: Cell, fut_b: Option, - fut_a: A::Future, + fut_a: Option, } impl ThenFuture @@ -69,10 +69,10 @@ where A: Service, B: Service>, { - fn new(fut_a: A::Future, b: Cell) -> Self { + fn new(a: A::Future, b: Cell) -> Self { ThenFuture { b, - fut_a, + fut_a: Some(a), fut_b: None, } } @@ -91,12 +91,14 @@ where return fut.poll(); } - match self.fut_a.poll() { + match self.fut_a.as_mut().expect("bug in actix-service").poll() { Ok(Async::Ready(resp)) => { + let _ = self.fut_a.take(); self.fut_b = Some(self.b.get_mut().call(Ok(resp))); self.poll() } Err(err) => { + let _ = self.fut_a.take(); self.fut_b = Some(self.b.get_mut().call(Err(err))); self.poll() }