From 1283d58ca9efb02db9d3908d3374b2ac17a6aee5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 13 Feb 2020 08:56:37 +0100 Subject: [PATCH] runtime: remove IN_TOKIO thread local variable tokio now has Handle::try_current() allowing us to generally check for a tokio runtime even if spawned by someone else Signed-off-by: Wolfgang Bumiller --- src/tools/runtime.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tools/runtime.rs b/src/tools/runtime.rs index a2e7cddf..23da7189 100644 --- a/src/tools/runtime.rs +++ b/src/tools/runtime.rs @@ -11,11 +11,11 @@ use tokio::runtime::{self, Runtime}; thread_local! { static HAS_RUNTIME: RefCell = RefCell::new(false); - static IN_TOKIO: RefCell = RefCell::new(false); } fn is_in_tokio() -> bool { - IN_TOKIO.with(|v| *v.borrow()) + tokio::runtime::Handle::try_current() + .is_ok() } fn has_runtime() -> bool { @@ -47,7 +47,6 @@ lazy_static! { runtime::Builder::new() .threaded_scheduler() .enable_all() - .on_thread_start(|| IN_TOKIO.with(|v| *v.borrow_mut() = true)) .build() .expect("failed to spawn tokio runtime") };