1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-02-17 13:33:31 +01:00

Poll boxed service call result immediately

This commit is contained in:
Nikolay Kim 2019-04-07 20:48:40 -07:00
parent bd814d6f80
commit a60112c71e
3 changed files with 22 additions and 5 deletions

View File

@ -1,5 +1,12 @@
# Changes
## [0.3.6] - 2019-04-07
### Changed
* Poll boxed service call result immediately
## [0.3.5] - 2019-03-29
### Added

View File

@ -1,6 +1,6 @@
[package]
name = "actix-service"
version = "0.3.5"
version = "0.3.6"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix Service"
keywords = ["network", "framework", "async", "futures"]

View File

@ -1,12 +1,14 @@
use futures::future::{err, ok, Either, FutureResult};
use futures::{Async, Future, IntoFuture, Poll};
use crate::{NewService, Service};
use futures::{Future, IntoFuture, Poll};
pub type BoxedService<Req, Res, Err> = Box<
Service<
Request = Req,
Response = Res,
Error = Err,
Future = Box<Future<Item = Res, Error = Err>>,
Future = Either<FutureResult<Res, Err>, Box<Future<Item = Res, Error = Err>>>,
>,
>;
@ -125,13 +127,21 @@ where
type Request = Req;
type Response = Res;
type Error = Err;
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
type Future = Either<
FutureResult<Self::Response, Self::Error>,
Box<Future<Item = Self::Response, Error = Self::Error>>,
>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
self.0.poll_ready()
}
fn call(&mut self, req: Self::Request) -> Self::Future {
Box::new(self.0.call(req))
let mut fut = self.0.call(req);
match fut.poll() {
Ok(Async::Ready(res)) => Either::A(ok(res)),
Err(e) => Either::A(err(e)),
Ok(Async::NotReady) => Either::B(Box::new(fut)),
}
}
}