Skip to content

refactor(runtime): use tokio LocalRuntime instead of MaskFutureAsSend#33273

Open
bartlomieju wants to merge 1 commit intomainfrom
refactor/tokio-local-runtime
Open

refactor(runtime): use tokio LocalRuntime instead of MaskFutureAsSend#33273
bartlomieju wants to merge 1 commit intomainfrom
refactor/tokio-local-runtime

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Upgrade tokio from 1.47.1 to 1.52.0 to get the stabilized LocalRuntime
  • Replace MaskFutureAsSend + rt.spawn() pattern with LocalRuntime::spawn_local() which natively supports !Send futures without unsafe
  • Replace deno_unsync::spawn / spawn_blocking / JoinHandle with tokio's native spawn_local / spawn_blocking / JoinHandle across the codebase
  • Convert inspector server from Runtime + LocalSet to LocalRuntime, eliminating the LocalSet indirection
  • Create libs/core/unsync.rs as a re-export module so all existing deno_core::unsync::spawn(...) callsites automatically use tokio::task::spawn_local

MaskFutureAsSend remains available (and used in cli/module_loader.rs) for the case where a !Send future must be moved across a thread boundary -- that's a Rust Send constraint, not a tokio runtime issue.

The sync primitives from deno_unsync (AtomicFlag, TaskQueue, UnsyncWaker, etc.) are unaffected and still used.

Test plan

  • cargo check passes
  • ./x fmt clean
  • CI green

🤖 Generated with Claude Code

Tokio 1.52 stabilized `LocalRuntime` which natively supports spawning
`!Send` futures without the unsafe `MaskFutureAsSend` workaround.

- Upgrade tokio from 1.47.1 to 1.52.0
- Convert `create_basic_runtime()` to return `LocalRuntime` via `build_local()`
- Replace `MaskFutureAsSend` + `rt.spawn()` with `rt.spawn_local()` in
  `create_and_run_current_thread_inner`
- Replace `deno_unsync::spawn` callsites with `tokio::task::spawn_local`
- Replace `deno_unsync::spawn_blocking` callsites with
  `tokio::task::spawn_blocking`
- Create `libs/core/unsync.rs` module that re-exports tokio's native task
  spawning alongside remaining deno_unsync utilities
- Convert inspector server from `Runtime` + `LocalSet` to `LocalRuntime`

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant