Skip to content

Commit 61939c7

Browse files
committed
Release future early for .and_then() and .then() combinators
1 parent e8a1664 commit 61939c7

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

actix-service/CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changes
22

3+
## [0.1.2] - 2018-12-12
4+
5+
### Fixed
6+
7+
* Release future early for `.and_then()` and `.then()` combinators
8+
9+
310
## [0.1.1] - 2018-12-09
411

512
### Added

actix-service/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "actix-service"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
authors = ["Nikolay Kim <[email protected]>"]
55
description = "Actix Service"
66
keywords = ["network", "framework", "async", "futures"]

actix-service/src/and_then.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ where
6161
{
6262
b: Cell<B>,
6363
fut_b: Option<B::Future>,
64-
fut_a: A::Future,
64+
fut_a: Option<A::Future>,
6565
}
6666

6767
impl<A, B, Request> AndThenFuture<A, B, Request>
6868
where
6969
A: Service<Request>,
7070
B: Service<A::Response, Error = A::Error>,
7171
{
72-
fn new(fut_a: A::Future, b: Cell<B>) -> Self {
72+
fn new(a: A::Future, b: Cell<B>) -> Self {
7373
AndThenFuture {
7474
b,
75-
fut_a,
75+
fut_a: Some(a),
7676
fut_b: None,
7777
}
7878
}
@@ -91,8 +91,9 @@ where
9191
return fut.poll();
9292
}
9393

94-
match self.fut_a.poll() {
94+
match self.fut_a.as_mut().expect("Bug in actix-service").poll() {
9595
Ok(Async::Ready(resp)) => {
96+
let _ = self.fut_a.take();
9697
self.fut_b = Some(self.b.get_mut().call(resp));
9798
self.poll()
9899
}

actix-service/src/then.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ where
6161
{
6262
b: Cell<B>,
6363
fut_b: Option<B::Future>,
64-
fut_a: A::Future,
64+
fut_a: Option<A::Future>,
6565
}
6666

6767
impl<A, B, Request> ThenFuture<A, B, Request>
6868
where
6969
A: Service<Request>,
7070
B: Service<Result<A::Response, A::Error>>,
7171
{
72-
fn new(fut_a: A::Future, b: Cell<B>) -> Self {
72+
fn new(a: A::Future, b: Cell<B>) -> Self {
7373
ThenFuture {
7474
b,
75-
fut_a,
75+
fut_a: Some(a),
7676
fut_b: None,
7777
}
7878
}
@@ -91,12 +91,14 @@ where
9191
return fut.poll();
9292
}
9393

94-
match self.fut_a.poll() {
94+
match self.fut_a.as_mut().expect("bug in actix-service").poll() {
9595
Ok(Async::Ready(resp)) => {
96+
let _ = self.fut_a.take();
9697
self.fut_b = Some(self.b.get_mut().call(Ok(resp)));
9798
self.poll()
9899
}
99100
Err(err) => {
101+
let _ = self.fut_a.take();
100102
self.fut_b = Some(self.b.get_mut().call(Err(err)));
101103
self.poll()
102104
}

0 commit comments

Comments
 (0)