Skip to content

Commit

Permalink
add Runtime::handle
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <wangrunji0408@163.com>
  • Loading branch information
wangrunji0408 committed Jun 5, 2024
1 parent bedfd03 commit 74a47a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## tokio [0.2.27] - 2024-06-05

### Added

- Add `Runtime::handle()`.

## tokio [0.2.26] - 2024-05-27

### Added
Expand Down
9 changes: 9 additions & 0 deletions madsim-tokio/src/sim/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FIXME: create a dedicated handle for tokio runtime instead of reusing madsim handle.
// tasks spawned with this handle are not correctly associated with the tokio runtime.
pub use madsim::runtime::Handle;
use madsim::task::{AbortHandle, JoinHandle};
use spin::Mutex;
Expand Down Expand Up @@ -42,13 +44,15 @@ impl Builder {
pub fn build(&mut self) -> io::Result<Runtime> {
Ok(Runtime {
abort_handles: Default::default(),
handle: Handle::current(),
})
}
}

/// A fake Tokio runtime.
pub struct Runtime {
abort_handles: Mutex<Vec<AbortHandle>>,
handle: Handle,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -81,6 +85,11 @@ impl Runtime {
// Madsim runtime is entered by default. No-op here.
EnterGuard(self)
}

/// Returns a handle to the runtime’s spawner.
pub fn handle(&self) -> &Handle {
&self.handle
}
}

impl Drop for Runtime {
Expand Down

0 comments on commit 74a47a9

Please # to comment.