Spawn onto local worker if possible

This commit is contained in:
Stjepan Glavina 2020-06-22 20:10:36 +02:00
parent 9e1a374559
commit 21fc108621
1 changed files with 5 additions and 5 deletions

View File

@ -102,11 +102,11 @@ impl<T: Send + 'static> Task<T> {
///
/// [`run()`]: `crate::run()`
pub fn spawn(future: impl Future<Output = T> + Send + 'static) -> Task<T> {
QUEUE.spawn(future)
// WORKER.with(|w| match &*w.borrow() {
// None => QUEUE.spawn(future),
// Some(w) => w.spawn(future),
// })
if WORKER.is_set() {
WORKER.with(|w| w.spawn_local(future))
} else {
QUEUE.spawn(future)
}
}
/// Spawns a future onto the blocking executor.