Cleanup in spawning tasks (#1181)

This commit is contained in:
Pierre Krieger 2019-06-24 12:18:07 +02:00 committed by GitHub
parent e4d43030eb
commit 6d5aa86cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,7 @@ use crate::{
} }
}; };
use fnv::FnvHashMap; use fnv::FnvHashMap;
use futures::{prelude::*, stream, sync::mpsc}; use futures::{prelude::*, future::Executor, stream, sync::mpsc};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{ use std::{
collections::hash_map::{Entry, OccupiedEntry}, collections::hash_map::{Entry, OccupiedEntry},
@ -35,7 +35,6 @@ use std::{
fmt, fmt,
mem mem
}; };
use tokio_executor::Executor;
mod tests; mod tests;
@ -361,11 +360,9 @@ impl<TInEvent, TOutEvent, TIntoHandler, TReachErr, THandlerErr, TUserData, TConn
// We try to use the default executor, but fall back to polling the task manually if // We try to use the default executor, but fall back to polling the task manually if
// no executor is available. This makes it possible to use the core in environments // no executor is available. This makes it possible to use the core in environments
// outside of tokio. // outside of tokio.
let mut executor = tokio_executor::DefaultExecutor::current(); let executor = tokio_executor::DefaultExecutor::current();
if executor.status().is_ok() { if let Err(err) = executor.execute(to_spawn) {
executor.spawn(to_spawn).expect("failed to create a node task"); self.local_spawns.push(err.into_future());
} else {
self.local_spawns.push(to_spawn);
} }
} }