From 1d69f96f3fee97bda46eca900fac4325efbea957 Mon Sep 17 00:00:00 2001 From: Abutalib Aghayev Date: Thu, 27 Oct 2022 15:55:51 -0400 Subject: [PATCH] rt: add a method to determine if the runtime is multi-threaded. --- tokio/src/runtime/handle.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tokio/src/runtime/handle.rs b/tokio/src/runtime/handle.rs index 91974252610..04512f3eb40 100644 --- a/tokio/src/runtime/handle.rs +++ b/tokio/src/runtime/handle.rs @@ -101,6 +101,15 @@ impl Handle { } } + /// Returns true if the currently running `Runtime` is multi-threaded and + /// false otherwise. + pub fn is_multi_threaded(&self) -> bool { + match self.inner { + scheduler::Handle::CurrentThread(_) => false, + scheduler::Handle::MultiThread(_) => true, + } + } + /// Returns a Handle view over the currently running Runtime /// /// Returns an error if no Runtime has been started