1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-21 15:46:48 +00:00

fix and and then new service

This commit is contained in:
Nikolay Kim 2018-08-24 13:18:05 -07:00
parent f2ef824011
commit 0eae4d84b1
3 changed files with 82 additions and 5 deletions

View file

@ -90,6 +90,79 @@ where
}
}
pub struct Fn2NewConfigurableService<F, S, Err, Fut, Cfg>
where
S: Service,
F: Fn(Cfg) -> Fut,
Fut: IntoFuture<Item = S, Error = Err>,
{
f: F,
err: marker::PhantomData<Err>,
cfg: marker::PhantomData<Cfg>,
fut: marker::PhantomData<Fut>,
s: marker::PhantomData<S>,
}
impl<F, S, Err, Fut, Cfg> Fn2NewConfigurableService<F, S, Err, Fut, Cfg>
where
S: Service,
F: Fn(Cfg) -> Fut + 'static,
Fut: IntoFuture<Item = S, Error = Err>,
{
fn new(f: F) -> Self {
Fn2NewConfigurableService{
f,
err: marker::PhantomData,
cfg: marker::PhantomData,
fut: marker::PhantomData,
s: marker::PhantomData
}
}
}
impl<F, S, Err, Fut, Cfg>
IntoNewConfigurableService<Fn2NewConfigurableService<F, S, Err, Fut, Cfg>>
for F
where
S: Service,
F: Fn(Cfg) -> Fut + 'static,
Fut: IntoFuture<Item = S, Error = Err>,
{
fn into_new_service(self) -> Fn2NewConfigurableService<F, S, Err, Fut, Cfg> {
Fn2NewConfigurableService::new(self)
}
}
impl<F, S, Err, Fut, Cfg> Clone for Fn2NewConfigurableService<F, S, Err, Fut, Cfg>
where
S: Service,
F: Fn(Cfg) -> Fut + Clone + 'static,
Fut: IntoFuture<Item = S, Error = Err>,
{
fn clone(&self) -> Self {
Self::new(self.f.clone())
}
}
impl<F, S, Err, Fut, Cfg> NewConfigurableService for Fn2NewConfigurableService<F, S, Err, Fut, Cfg>
where
S: Service,
F: Fn(Cfg) -> Fut,
Fut: IntoFuture<Item = S, Error = Err>,
{
type Request = S::Request;
type Response = S::Response;
type Error = S::Error;
type Service = S;
type Config = Cfg;
type InitError = Err;
type Future = Fut::Future;
fn new_service(&self, cfg: Cfg) -> Self::Future {
(self.f)(cfg).into_future()
}
}
pub struct FnNewConfigurableService<F, Req, Resp, Err, IErr, Fut, Cfg>
where
F: Fn(Req) -> Fut,

View file

@ -60,7 +60,7 @@ pub mod service;
pub mod ssl;
mod worker;
pub use configurable::NewConfigurableService;
pub use configurable::{NewConfigurableService, IntoNewConfigurableService};
pub use connector::{Connector, ConnectorError};
pub use server::Server;
pub use service::{IntoNewService, IntoService, NewServiceExt};

View file

@ -521,12 +521,16 @@ where
type Error = B::InitError;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
if let Async::Ready(service) = self.fut_a.poll()? {
self.a = Some(service);
if self.a.is_none() {
if let Async::Ready(service) = self.fut_a.poll()? {
self.a = Some(service);
}
}
if let Async::Ready(service) = self.fut_b.poll()? {
self.b = Some(service);
if self.b.is_none() {
if let Async::Ready(service) = self.fut_b.poll()? {
self.b = Some(service);
}
}
if self.a.is_some() && self.b.is_some() {