Add connect_timeout to async and sync clients

This commit is contained in:
Sean McArthur
2019-02-20 12:35:12 -08:00
parent 66db8d6283
commit 9e2b56ba56
4 changed files with 75 additions and 12 deletions

View File

@@ -281,12 +281,28 @@ impl ClientBuilder {
///
/// Pass `None` to disable timeout.
pub fn timeout<T>(mut self, timeout: T) -> ClientBuilder
where T: Into<Option<Duration>>,
where
T: Into<Option<Duration>>,
{
self.timeout = Timeout(timeout.into());
self
}
/// Set a timeout for only the connect phase of a `Client`.
///
/// Default is `None`.
pub fn connect_timeout<T>(self, timeout: T) -> ClientBuilder
where
T: Into<Option<Duration>>,
{
let timeout = timeout.into();
if let Some(dur) = timeout {
self.with_inner(|inner| inner.connect_timeout(dur))
} else {
self
}
}
fn with_inner<F>(mut self, func: F) -> ClientBuilder
where
F: FnOnce(async_impl::ClientBuilder) -> async_impl::ClientBuilder,