Executor + Send (#1399)

This commit is contained in:
Pierre Krieger
2020-01-20 15:22:47 +01:00
committed by GitHub
parent f89683419a
commit 7d0c80fce1
4 changed files with 8 additions and 8 deletions

View File

@ -572,7 +572,7 @@ impl<'a> PollParameters for SwarmPollParameters<'a> {
pub struct SwarmBuilder<TTransport, TBehaviour> {
incoming_limit: Option<u32>,
executor: Option<Box<dyn Executor>>,
executor: Option<Box<dyn Executor + Send>>,
local_peer_id: PeerId,
transport: TTransport,
behaviour: TBehaviour,
@ -626,13 +626,13 @@ where TBehaviour: NetworkBehaviour,
/// Sets the executor to use to spawn background tasks.
///
/// By default, uses a threads pool.
pub fn executor(mut self, executor: impl Executor + 'static) -> Self {
pub fn executor(mut self, executor: impl Executor + Send + 'static) -> Self {
self.executor = Some(Box::new(executor));
self
}
/// Shortcut for calling `executor` with an object that calls the given closure.
pub fn executor_fn(mut self, executor: impl Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + 'static) -> Self {
pub fn executor_fn(mut self, executor: impl Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + 'static) -> Self {
struct SpawnImpl<F>(F);
impl<F: Fn(Pin<Box<dyn Future<Output = ()> + Send>>)> Executor for SpawnImpl<F> {
fn exec(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) {