mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +01:00
calculate client request timeout
This commit is contained in:
parent
bccd7c7671
commit
1af5aa3a3e
@ -71,7 +71,7 @@ pub struct SendRequest {
|
|||||||
conn: Option<Addr<ClientConnector>>,
|
conn: Option<Addr<ClientConnector>>,
|
||||||
conn_timeout: Duration,
|
conn_timeout: Duration,
|
||||||
wait_timeout: Duration,
|
wait_timeout: Duration,
|
||||||
timeout: Option<Delay>,
|
timeout: Option<Duration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendRequest {
|
impl SendRequest {
|
||||||
@ -115,7 +115,7 @@ impl SendRequest {
|
|||||||
/// Request timeout is the total time before a response must be received.
|
/// Request timeout is the total time before a response must be received.
|
||||||
/// Default value is 5 seconds.
|
/// Default value is 5 seconds.
|
||||||
pub fn timeout(mut self, timeout: Duration) -> Self {
|
pub fn timeout(mut self, timeout: Duration) -> Self {
|
||||||
self.timeout = Some(Delay::new(Instant::now() + timeout));
|
self.timeout = Some(timeout);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,9 +185,10 @@ impl Future for SendRequest {
|
|||||||
_ => IoBody::Done,
|
_ => IoBody::Done,
|
||||||
};
|
};
|
||||||
|
|
||||||
let timeout = self.timeout.take().unwrap_or_else(|| {
|
let timeout = self
|
||||||
Delay::new(Instant::now() + Duration::from_secs(5))
|
.timeout
|
||||||
});
|
.take()
|
||||||
|
.unwrap_or_else(|| Duration::from_secs(5));
|
||||||
|
|
||||||
let pl = Box::new(Pipeline {
|
let pl = Box::new(Pipeline {
|
||||||
body,
|
body,
|
||||||
@ -201,7 +202,7 @@ impl Future for SendRequest {
|
|||||||
decompress: None,
|
decompress: None,
|
||||||
should_decompress: self.req.response_decompress(),
|
should_decompress: self.req.response_decompress(),
|
||||||
write_state: RunningState::Running,
|
write_state: RunningState::Running,
|
||||||
timeout: Some(timeout),
|
timeout: Some(Delay::new(Instant::now() + timeout)),
|
||||||
close: self.req.method() == &Method::HEAD,
|
close: self.req.method() == &Method::HEAD,
|
||||||
});
|
});
|
||||||
self.state = State::Send(pl);
|
self.state = State::Send(pl);
|
||||||
|
Loading…
Reference in New Issue
Block a user