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

@ -309,7 +309,7 @@ where
{ {
/// Creates a new empty collection. If `executor` is `Some`, uses the given executor to spawn /// Creates a new empty collection. If `executor` is `Some`, uses the given executor to spawn
/// tasks. Otherwise, runs tasks locally. /// tasks. Otherwise, runs tasks locally.
pub fn new(executor: Option<Box<dyn Executor>>) -> Self { pub fn new(executor: Option<Box<dyn Executor + Send>>) -> Self {
CollectionStream { CollectionStream {
inner: tasks::Manager::new(executor), inner: tasks::Manager::new(executor),
nodes: Default::default(), nodes: Default::default(),

View File

@ -688,7 +688,7 @@ where
TPeerId: Eq + Hash + Clone, TPeerId: Eq + Hash + Clone,
{ {
/// Creates a new node events stream. /// Creates a new node events stream.
pub fn new(transport: TTrans, local_peer_id: TPeerId, executor: Option<Box<dyn Executor>>) -> Self { pub fn new(transport: TTrans, local_peer_id: TPeerId, executor: Option<Box<dyn Executor + Send>>) -> Self {
// TODO: with_capacity? // TODO: with_capacity?
Network { Network {
listeners: ListenersStream::new(transport), listeners: ListenersStream::new(transport),
@ -706,7 +706,7 @@ where
/// Creates a new node event stream with incoming connections limit. /// Creates a new node event stream with incoming connections limit.
pub fn new_with_incoming_limit(transport: TTrans, pub fn new_with_incoming_limit(transport: TTrans,
local_peer_id: TPeerId, executor: Option<Box<dyn Executor>>, incoming_limit: Option<u32>) -> Self local_peer_id: TPeerId, executor: Option<Box<dyn Executor + Send>>, incoming_limit: Option<u32>) -> Self
{ {
Network { Network {
incoming_limit, incoming_limit,

View File

@ -65,7 +65,7 @@ pub struct Manager<I, O, H, E, HE, T, C = PeerId> {
/// Custom executor where we spawn the nodes' tasks. If `None`, then we push tasks to the /// Custom executor where we spawn the nodes' tasks. If `None`, then we push tasks to the
/// `local_spawns` list instead. /// `local_spawns` list instead.
executor: Option<Box<dyn Executor>>, executor: Option<Box<dyn Executor + Send>>,
/// If no executor is available, we move tasks to this set, and futures are polled on the /// If no executor is available, we move tasks to this set, and futures are polled on the
/// current thread instead. /// current thread instead.
@ -136,7 +136,7 @@ pub enum Event<'a, I, O, H, E, HE, T, C = PeerId> {
impl<I, O, H, E, HE, T, C> Manager<I, O, H, E, HE, T, C> { impl<I, O, H, E, HE, T, C> Manager<I, O, H, E, HE, T, C> {
/// Creates a new task manager. If `Some` is passed, uses the given executor to spawn tasks. /// Creates a new task manager. If `Some` is passed, uses the given executor to spawn tasks.
/// Otherwise, background tasks are executed locally when you call `poll`. /// Otherwise, background tasks are executed locally when you call `poll`.
pub fn new(executor: Option<Box<dyn Executor>>) -> Self { pub fn new(executor: Option<Box<dyn Executor + Send>>) -> Self {
let (tx, rx) = mpsc::channel(1); let (tx, rx) = mpsc::channel(1);
Self { Self {
tasks: FnvHashMap::default(), tasks: FnvHashMap::default(),

View File

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