Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pool: use Executor trait instead of concrete type #47

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/client/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,15 +1413,16 @@ impl Builder {
B: Body + Send,
B::Data: Send,
{
let exec = self.exec.clone();
Client {
config: self.client_config,
exec: self.exec.clone(),
exec: exec.clone(),
#[cfg(feature = "http1")]
h1_builder: self.h1_builder.clone(),
#[cfg(feature = "http2")]
h2_builder: self.h2_builder.clone(),
connector,
pool: pool::Pool::new(self.pool_config, &self.exec),
pool: pool::Pool::new(self.pool_config, exec),
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tokio::time::{Duration, Instant, Interval};
use futures_channel::oneshot;
use tracing::{debug, trace};

use crate::common::{exec::Exec, ready};
use crate::common::{exec, exec::Exec, ready};

// FIXME: allow() required due to `impl Trait` leaking types to this lint
#[allow(missing_debug_implementations)]
Expand Down Expand Up @@ -121,7 +121,11 @@ impl Config {
}

impl<T, K: Key> Pool<T, K> {
pub fn new(config: Config, __exec: &Exec) -> Pool<T, K> {
pub fn new<E>(config: Config, executor: E) -> Pool<T, K>
where
E: hyper::rt::Executor<exec::BoxSendFuture> + Send + Sync + Clone + 'static,
{
let exec = Exec::new(executor);
let inner = if config.is_enabled() {
Some(Arc::new(Mutex::new(PoolInner {
connecting: HashSet::new(),
Expand All @@ -131,7 +135,7 @@ impl<T, K: Key> Pool<T, K> {
max_idle_per_host: config.max_idle_per_host,
waiters: HashMap::new(),
#[cfg(feature = "runtime")]
exec: __exec.clone(),
exec,
timeout: config.idle_timeout,
})))
} else {
Expand Down Expand Up @@ -830,7 +834,7 @@ mod tests {
use std::time::Duration;

use super::{Connecting, Key, Pool, Poolable, Reservation, WeakOpt};
use crate::common::exec::Exec;
use crate::rt::tokio_executor::TokioExecutor;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct KeyImpl(http::uri::Scheme, http::uri::Authority);
Expand Down Expand Up @@ -876,7 +880,7 @@ mod tests {
idle_timeout: Some(Duration::from_millis(100)),
max_idle_per_host: max_idle,
},
&Exec::Default,
TokioExecutor::new(),
);
pool.no_timer();
pool
Expand Down Expand Up @@ -977,7 +981,7 @@ mod tests {
idle_timeout: Some(Duration::from_millis(10)),
max_idle_per_host: std::usize::MAX,
},
&Exec::Default,
TokioExecutor::new(),
);

let key = host_key("foo");
Expand Down