From 6194d6fc5d5d0f8f6cd8640a47afaa55bc9841e1 Mon Sep 17 00:00:00 2001 From: oblique Date: Sat, 25 Jul 2020 12:48:36 +0300 Subject: [PATCH] Allow running `Task::local` from any thread --- src/lib.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b625fa6b..6dcd9261 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,11 +121,16 @@ pub fn run(future: impl Future) -> T { #[cfg(not(feature = "tokio02"))] fn setup(num_threads: usize, shutdown: Receiver<()>, future: impl Future) -> T { let ex = Executor::new(); - let local_ex = LocalExecutor::new(); Parallel::new() - .each(0..num_threads, |_| ex.run(shutdown.recv())) - .finish(|| ex.enter(|| local_ex.run(future))) + .each(0..num_threads, |_| { + let local_ex = LocalExecutor::new(); + local_ex.enter(|| ex.run(shutdown.recv())) + }) + .finish(|| { + let local_ex = LocalExecutor::new(); + local_ex.enter(|| ex.run(future)) + }) .1 } @@ -140,11 +145,19 @@ fn setup(num_threads: usize, shutdown: Receiver<()>, future: impl Future