Skip to content

Commit 1d00bb2

Browse files
committed
chore(client): re-enable client's custom executor config
1 parent 283522b commit 1d00bb2

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/client/conn.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,15 @@ impl Builder {
453453
}
454454
}
455455

456-
/*
457456
/// Provide an executor to execute background HTTP2 tasks.
458457
pub fn executor<E>(&mut self, exec: E) -> &mut Builder
459458
where
460-
E: Executor<Box<dyn Future<Item=(), Error=()> + Send>> + Send + Sync + 'static,
459+
for<'a> &'a E: tokio_executor::Executor,
460+
E: Send + Sync + 'static,
461461
{
462462
self.exec = Exec::Executor(Arc::new(exec));
463463
self
464464
}
465-
*/
466465

467466
pub(super) fn h1_writev(&mut self, enabled: bool) -> &mut Builder {
468467
self.h1_writev = enabled;

src/client/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,16 +1011,15 @@ impl Builder {
10111011
self
10121012
}
10131013

1014-
/*
10151014
/// Provide an executor to execute background `Connection` tasks.
10161015
pub fn executor<E>(&mut self, exec: E) -> &mut Self
10171016
where
1018-
E: Executor<Box<dyn Future<Item=(), Error=()> + Send>> + Send + Sync + 'static,
1017+
for<'a> &'a E: tokio_executor::Executor,
1018+
E: Send + Sync + 'static,
10191019
{
10201020
self.conn_builder.executor(exec);
10211021
self
10221022
}
1023-
*/
10241023

10251024
/// Builder a client with this configuration and the default `HttpConnector`.
10261025
#[cfg(feature = "runtime")]

src/common/exec.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::future::Future;
33
use std::pin::Pin;
44
use std::sync::Arc;
55

6-
use tokio_executor::TypedExecutor;
6+
use tokio_executor::{SpawnError, TypedExecutor};
77

88
use crate::body::Payload;
99
use crate::proto::h2::server::H2Stream;
@@ -18,12 +18,27 @@ pub trait NewSvcExec<I, N, S: Service, E, W: Watcher<I, S, E>>: Clone {
1818
fn execute_new_svc(&mut self, fut: NewSvcTask<I, N, S, E, W>) -> crate::Result<()>;
1919
}
2020

21+
type BoxFuture = Pin<Box<dyn Future<Output=()> + Send>>;
22+
23+
pub trait SharedExecutor {
24+
fn shared_spawn(&self, future: BoxFuture) -> Result<(), SpawnError>;
25+
}
26+
27+
impl<E> SharedExecutor for E
28+
where
29+
for<'a> &'a E: tokio_executor::Executor,
30+
{
31+
fn shared_spawn(mut self: &Self, future: BoxFuture) -> Result<(), SpawnError> {
32+
tokio_executor::Executor::spawn(&mut self, future)
33+
}
34+
}
35+
2136
// Either the user provides an executor for background tasks, or we use
2237
// `tokio::spawn`.
2338
#[derive(Clone)]
2439
pub enum Exec {
2540
Default,
26-
Executor(Arc<dyn TypedExecutor<Pin<Box<dyn Future<Output=()> + Send>>> + Send + Sync>),
41+
Executor(Arc<dyn SharedExecutor + Send + Sync>),
2742
}
2843

2944
// ===== impl Exec =====
@@ -73,14 +88,11 @@ impl Exec {
7388
}
7489
},
7590
Exec::Executor(ref e) => {
76-
unimplemented!("custom executor exec");
77-
/* XXX: needs mut
78-
e.spawn(Box::pin(fut))
91+
e.shared_spawn(Box::pin(fut))
7992
.map_err(|err| {
8093
warn!("executor error: {:?}", err);
8194
crate::Error::new_execute("custom executor failed")
8295
})
83-
*/
8496
},
8597
}
8698
}

0 commit comments

Comments
 (0)