Skip to content

Commit

Permalink
fix try_current
Browse files Browse the repository at this point in the history
  • Loading branch information
kwannoel committed Sep 30, 2024
1 parent ea9dabd commit ff59da8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion madsim-tokio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madsim-tokio"
version = "0.2.29"
version = "0.2.30"
edition = "2021"
authors = ["Runji Wang <[email protected]>"]
description = "The `tokio` simulator on madsim."
Expand Down
9 changes: 7 additions & 2 deletions madsim-tokio/src/sim/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use madsim::runtime::Handle as MadsimHandle;
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 {}
Expand Down Expand Up @@ -111,6 +111,8 @@ impl Drop for Runtime {
}
}

pub struct TryCurrentError;

/// Handle to the tokio runtime.
///
/// FIXME: tasks spawned with this handle are not correctly associated with the tokio runtime.
Expand All @@ -125,7 +127,10 @@ impl Handle {

/// Returns a handle to the current runtime.
pub fn try_current() -> Result<Self, TryCurrentError> {
Ok(Handle)
match MadsimHandle::try_current() {
Ok(_) => Ok(Handle),
Err(_e) => Err(TryCurrentError),
}
}

/// Enters the runtime context.
Expand Down

0 comments on commit ff59da8

Please sign in to comment.