diff --git a/tokio/src/runtime/handle.rs b/tokio/src/runtime/handle.rs index 91974252610..07150927f8f 100644 --- a/tokio/src/runtime/handle.rs +++ b/tokio/src/runtime/handle.rs @@ -101,6 +101,33 @@ impl Handle { } } + /// Returns true if the current `Runtime` is multi-threaded and false + /// otherwise. + /// + /// ``` + /// use tokio::runtime::Handle; + /// + /// #[tokio::main(flavor = "current_thread")] + /// async fn main() { + /// assert!(!Handle::current().is_multi_threaded()); + /// } + /// ``` + /// + /// ``` + /// use tokio::runtime::Handle; + /// + /// #[tokio::main(flavor = "multi_thread", worker_threads = 4)] + /// async fn main() { + /// assert!(Handle::current().is_multi_threaded()); + /// } + /// ``` + 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