From 1af5aa3a3ea4d897ca598b0528e1c70ddfc46cff Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 17 Jul 2018 02:30:21 +0600 Subject: [PATCH] calculate client request timeout --- src/client/pipeline.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/client/pipeline.rs b/src/client/pipeline.rs index 2192d474c..c3f3bf4cd 100644 --- a/src/client/pipeline.rs +++ b/src/client/pipeline.rs @@ -71,7 +71,7 @@ pub struct SendRequest { conn: Option>, conn_timeout: Duration, wait_timeout: Duration, - timeout: Option, + timeout: Option, } impl SendRequest { @@ -115,7 +115,7 @@ impl SendRequest { /// Request timeout is the total time before a response must be received. /// Default value is 5 seconds. pub fn timeout(mut self, timeout: Duration) -> Self { - self.timeout = Some(Delay::new(Instant::now() + timeout)); + self.timeout = Some(timeout); self } @@ -185,9 +185,10 @@ impl Future for SendRequest { _ => IoBody::Done, }; - let timeout = self.timeout.take().unwrap_or_else(|| { - Delay::new(Instant::now() + Duration::from_secs(5)) - }); + let timeout = self + .timeout + .take() + .unwrap_or_else(|| Duration::from_secs(5)); let pl = Box::new(Pipeline { body, @@ -201,7 +202,7 @@ impl Future for SendRequest { decompress: None, should_decompress: self.req.response_decompress(), write_state: RunningState::Running, - timeout: Some(timeout), + timeout: Some(Delay::new(Instant::now() + timeout)), close: self.req.method() == &Method::HEAD, }); self.state = State::Send(pl);