1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-27 00:27:43 +02:00

depend on git repo

This commit is contained in:
Nikolay Kim
2019-02-03 11:33:26 -08:00
parent 5b8446105f
commit 406088524e
2 changed files with 15 additions and 8 deletions

View File

@ -3,6 +3,7 @@
//! If the response does not complete within the specified timeout, the response
//! will be aborted.
use std::fmt;
use std::marker::PhantomData;
use std::time::Duration;
use actix_service::{NewTransform, Service, Transform};
@ -12,8 +13,9 @@ use tokio_timer::{clock, Delay};
/// Applies a timeout to requests.
#[derive(Debug, Clone)]
pub struct Timeout {
pub struct Timeout<E = ()> {
timeout: Duration,
_t: PhantomData<E>,
}
/// Timeout error
@ -54,20 +56,23 @@ impl<E: PartialEq> PartialEq for TimeoutError<E> {
}
}
impl Timeout {
impl<E> Timeout<E> {
pub fn new(timeout: Duration) -> Self {
Timeout { timeout }
Timeout {
timeout,
_t: PhantomData,
}
}
}
impl<S> NewTransform<S> for Timeout
impl<S, E> NewTransform<S> for Timeout<E>
where
S: Service,
{
type Request = S::Request;
type Response = S::Response;
type Error = TimeoutError<S::Error>;
type InitError = ();
type InitError = E;
type Transform = TimeoutService;
type Future = FutureResult<Self::Transform, Self::InitError>;