From ea9dabd72add06837703294796c4afaf7bd75915 Mon Sep 17 00:00:00 2001 From: Noel Kwan <47273164+kwannoel@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:47:00 +0800 Subject: [PATCH] fix(madsim-tokio): add `try_current` (#224) * add try_current * bump madsim-tokio version to 0.2.29 --- madsim-tokio/Cargo.toml | 2 +- madsim-tokio/src/sim/runtime.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/madsim-tokio/Cargo.toml b/madsim-tokio/Cargo.toml index 87fc4d8..83e0279 100644 --- a/madsim-tokio/Cargo.toml +++ b/madsim-tokio/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "madsim-tokio" -version = "0.2.28" +version = "0.2.29" edition = "2021" authors = ["Runji Wang "] description = "The `tokio` simulator on madsim." diff --git a/madsim-tokio/src/sim/runtime.rs b/madsim-tokio/src/sim/runtime.rs index aef55ae..4a95dc3 100644 --- a/madsim-tokio/src/sim/runtime.rs +++ b/madsim-tokio/src/sim/runtime.rs @@ -1,6 +1,7 @@ use madsim::task::{AbortHandle, JoinHandle}; use spin::Mutex; use std::{future::Future, io}; +use tokio::runtime::TryCurrentError; /// Builds Tokio Runtime with custom configuration values. pub struct Builder {} @@ -118,10 +119,15 @@ pub struct Handle; impl Handle { /// Returns a handle to the current runtime. - pub fn current() -> Handle { + pub fn current() -> Self { Handle } + /// Returns a handle to the current runtime. + pub fn try_current() -> Result { + Ok(Handle) + } + /// Enters the runtime context. /// /// FIXME: This is currently a no-op.