mirror of
https://github.com/actix/actix-web.git
synced 2024-12-21 23:56:35 +00:00
fix and and then new service
This commit is contained in:
parent
f2ef824011
commit
0eae4d84b1
3 changed files with 82 additions and 5 deletions
|
@ -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>
|
pub struct FnNewConfigurableService<F, Req, Resp, Err, IErr, Fut, Cfg>
|
||||||
where
|
where
|
||||||
F: Fn(Req) -> Fut,
|
F: Fn(Req) -> Fut,
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub mod service;
|
||||||
pub mod ssl;
|
pub mod ssl;
|
||||||
mod worker;
|
mod worker;
|
||||||
|
|
||||||
pub use configurable::NewConfigurableService;
|
pub use configurable::{NewConfigurableService, IntoNewConfigurableService};
|
||||||
pub use connector::{Connector, ConnectorError};
|
pub use connector::{Connector, ConnectorError};
|
||||||
pub use server::Server;
|
pub use server::Server;
|
||||||
pub use service::{IntoNewService, IntoService, NewServiceExt};
|
pub use service::{IntoNewService, IntoService, NewServiceExt};
|
||||||
|
|
|
@ -521,12 +521,16 @@ where
|
||||||
type Error = B::InitError;
|
type Error = B::InitError;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
if let Async::Ready(service) = self.fut_a.poll()? {
|
if self.a.is_none() {
|
||||||
self.a = Some(service);
|
if let Async::Ready(service) = self.fut_a.poll()? {
|
||||||
|
self.a = Some(service);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Async::Ready(service) = self.fut_b.poll()? {
|
if self.b.is_none() {
|
||||||
self.b = Some(service);
|
if let Async::Ready(service) = self.fut_b.poll()? {
|
||||||
|
self.b = Some(service);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.a.is_some() && self.b.is_some() {
|
if self.a.is_some() && self.b.is_some() {
|
||||||
|
|
Loading…
Reference in a new issue