From 1d00bb29d4f5d123ddd04d7f78de3b1a98fe7dfb Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 19 Jul 2019 14:18:10 -0700 Subject: [PATCH] chore(client): re-enable client's custom executor config --- src/client/conn.rs | 5 ++--- src/client/mod.rs | 5 ++--- src/common/exec.rs | 24 ++++++++++++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/client/conn.rs b/src/client/conn.rs index e9fd30d1..e171f31a 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -453,16 +453,15 @@ impl Builder { } } - /* /// Provide an executor to execute background HTTP2 tasks. pub fn executor(&mut self, exec: E) -> &mut Builder where - E: Executor + Send>> + Send + Sync + 'static, + for<'a> &'a E: tokio_executor::Executor, + E: Send + Sync + 'static, { self.exec = Exec::Executor(Arc::new(exec)); self } - */ pub(super) fn h1_writev(&mut self, enabled: bool) -> &mut Builder { self.h1_writev = enabled; diff --git a/src/client/mod.rs b/src/client/mod.rs index a617e9f5..6309d999 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1011,16 +1011,15 @@ impl Builder { self } - /* /// Provide an executor to execute background `Connection` tasks. pub fn executor(&mut self, exec: E) -> &mut Self where - E: Executor + Send>> + Send + Sync + 'static, + for<'a> &'a E: tokio_executor::Executor, + E: Send + Sync + 'static, { self.conn_builder.executor(exec); self } - */ /// Builder a client with this configuration and the default `HttpConnector`. #[cfg(feature = "runtime")] diff --git a/src/common/exec.rs b/src/common/exec.rs index a0e121b9..a91333f4 100644 --- a/src/common/exec.rs +++ b/src/common/exec.rs @@ -3,7 +3,7 @@ use std::future::Future; use std::pin::Pin; use std::sync::Arc; -use tokio_executor::TypedExecutor; +use tokio_executor::{SpawnError, TypedExecutor}; use crate::body::Payload; use crate::proto::h2::server::H2Stream; @@ -18,12 +18,27 @@ pub trait NewSvcExec>: Clone { fn execute_new_svc(&mut self, fut: NewSvcTask) -> crate::Result<()>; } +type BoxFuture = Pin + Send>>; + +pub trait SharedExecutor { + fn shared_spawn(&self, future: BoxFuture) -> Result<(), SpawnError>; +} + +impl SharedExecutor for E +where + for<'a> &'a E: tokio_executor::Executor, +{ + fn shared_spawn(mut self: &Self, future: BoxFuture) -> Result<(), SpawnError> { + tokio_executor::Executor::spawn(&mut self, future) + } +} + // Either the user provides an executor for background tasks, or we use // `tokio::spawn`. #[derive(Clone)] pub enum Exec { Default, - Executor(Arc + Send>>> + Send + Sync>), + Executor(Arc), } // ===== impl Exec ===== @@ -73,14 +88,11 @@ impl Exec { } }, Exec::Executor(ref e) => { - unimplemented!("custom executor exec"); - /* XXX: needs mut - e.spawn(Box::pin(fut)) + e.shared_spawn(Box::pin(fut)) .map_err(|err| { warn!("executor error: {:?}", err); crate::Error::new_execute("custom executor failed") }) - */ }, } }