feat(client): rename client::Builder pool options (#2142)

- Renamed `keep_alive_timeout` to `pool_idle_timeout`.
- Renamed `max_idle_per_host` to `pool_max_idle_per_host`.
- Deprecated `keep_alive(bool)` due to confusing name. To disable the
  connection pool, call `pool_max_idle_per_host(0)`.
This commit is contained in:
Sean McArthur
2020-02-27 14:25:06 -08:00
committed by GitHub
parent 48102d6122
commit a82fd6c94a
4 changed files with 63 additions and 45 deletions

View File

@@ -88,14 +88,19 @@ struct WeakOpt<T>(Option<Weak<T>>);
#[derive(Clone, Copy, Debug)]
pub(super) struct Config {
pub(super) enabled: bool,
pub(super) keep_alive_timeout: Option<Duration>,
pub(super) idle_timeout: Option<Duration>,
pub(super) max_idle_per_host: usize,
}
impl Config {
pub(super) fn is_enabled(&self) -> bool {
self.max_idle_per_host > 0
}
}
impl<T> Pool<T> {
pub fn new(config: Config, __exec: &Exec) -> Pool<T> {
let inner = if config.enabled {
let inner = if config.is_enabled() {
Some(Arc::new(Mutex::new(PoolInner {
connecting: HashSet::new(),
idle: HashMap::new(),
@@ -105,7 +110,7 @@ impl<T> Pool<T> {
waiters: HashMap::new(),
#[cfg(feature = "runtime")]
exec: __exec.clone(),
timeout: config.keep_alive_timeout,
timeout: config.idle_timeout,
})))
} else {
None
@@ -797,8 +802,7 @@ mod tests {
fn pool_max_idle_no_timer<T>(max_idle: usize) -> Pool<T> {
let pool = Pool::new(
super::Config {
enabled: true,
keep_alive_timeout: Some(Duration::from_millis(100)),
idle_timeout: Some(Duration::from_millis(100)),
max_idle_per_host: max_idle,
},
&Exec::Default,
@@ -900,8 +904,7 @@ mod tests {
let pool = Pool::new(
super::Config {
enabled: true,
keep_alive_timeout: Some(Duration::from_millis(10)),
idle_timeout: Some(Duration::from_millis(10)),
max_idle_per_host: std::usize::MAX,
},
&Exec::Default,