Skip to content

Commit

Permalink
Release future early for .and_then() and .then() combinators
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Dec 13, 2018
1 parent e8a1664 commit 61939c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
7 changes: 7 additions & 0 deletions actix-service/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion actix-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "actix-service"
version = "0.1.1"
version = "0.1.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix Service"
keywords = ["network", "framework", "async", "futures"]
Expand Down
9 changes: 5 additions & 4 deletions actix-service/src/and_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ where
{
b: Cell<B>,
fut_b: Option<B::Future>,
fut_a: A::Future,
fut_a: Option<A::Future>,
}

impl<A, B, Request> AndThenFuture<A, B, Request>
where
A: Service<Request>,
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 {
b,
fut_a,
fut_a: Some(a),
fut_b: None,
}
}
Expand All @@ -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()
}
Expand Down
10 changes: 6 additions & 4 deletions actix-service/src/then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ where
{
b: Cell<B>,
fut_b: Option<B::Future>,
fut_a: A::Future,
fut_a: Option<A::Future>,
}

impl<A, B, Request> ThenFuture<A, B, Request>
where
A: Service<Request>,
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 {
b,
fut_a,
fut_a: Some(a),
fut_b: None,
}
}
Expand All @@ -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()
}
Expand Down

0 comments on commit 61939c7

Please sign in to comment.