Skip to content

tokio: Stabilize LocalRuntime#7557

Merged
Darksonn merged 6 commits intotokio-rs:masterfrom
Daksh14:stablize-local-thread
Apr 2, 2026
Merged

tokio: Stabilize LocalRuntime#7557
Darksonn merged 6 commits intotokio-rs:masterfrom
Daksh14:stablize-local-thread

Conversation

@Daksh14
Copy link
Copy Markdown
Contributor

@Daksh14 Daksh14 commented Aug 29, 2025

Motivation

After LocalRuntime was implemented as per the issue #6739 I think its time to stabilize it so we don't need to set the RUSTFLAGS when using it

Solution

Remove cfg unstable in docs and places where it was initially implemented, I have tested the macro

#[tokio::main(flavor = "local")]
async fn main() {
    println!("hello");
}

And using it just like

use tokio::runtime::LocalRuntime;

fn main() {
    let rt = LocalRuntime::new().unwrap();

    rt.block_on(async {
        println!("{:?}", "hello");
    });

    println!("hello");
}

@Daksh14 Daksh14 changed the title tokio: Stablize LocalRuntime tokio: Stabliize LocalRuntime Aug 29, 2025
@Daksh14 Daksh14 changed the title tokio: Stabliize LocalRuntime tokio: Stabilize LocalRuntime Aug 29, 2025
@Daksh14 Daksh14 force-pushed the stablize-local-thread branch 7 times, most recently from 83f5586 to 4f436e0 Compare August 29, 2025 08:10
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime labels Aug 29, 2025
@ADD-SP
Copy link
Copy Markdown
Member

ADD-SP commented Aug 29, 2025

I think the LocalRuntime is useful. However, I'd like to hit the brakes for now, there are more works we need to do before stabilizing it in the code. Removing the tokio_unstable from the code should be the last work for stabilization.

@ADD-SP
Copy link
Copy Markdown
Member

ADD-SP commented Aug 29, 2025

  1. Shall we deprecate the tokio::task::LocalSet and tokio_util::task::LocalPoolHandle?
  2. There are many overlaps between the LocalRuntime and CurrentThreadRuntime, what's the future of the current thread runtime? Any guideline to downstream?
  3. Shall we add the tokio::spawn_local? What's the behavior when it is called from current_thread or multi_thread runtime?
  4. Any other impacts to the existing usage of tokio, tokio-stream, and tokio-util?

@Darksonn
Copy link
Copy Markdown
Member

Relevant to this: #6741

@Daksh14 Daksh14 marked this pull request as draft September 1, 2025 17:25
@takeoverjp
Copy link
Copy Markdown

takeoverjp commented Sep 2, 2025

LocalRuntime is very helpful for me, thanks!

I think it's better to add description of flavor = "local in the doc comment of tokio::test as well as tokio::main.
Like the following:
(Sorry, but I couldn't comment it on source code due to GitHub UI)

/// # local runtime
///
/// The default test runtime is the [local runtime]. The [local runtime] is similar to the current-thread
/// but supports[`task::spawn_local`](../tokio/task/fn.spawn_local.html).
///
/// ```no_run
/// #[tokio::test(flavor = "local")]
/// async fn my_test() {
///     assert!(true);
/// }
/// ```

@Daksh14 Daksh14 closed this Oct 10, 2025
@Daksh14 Daksh14 deleted the stablize-local-thread branch October 17, 2025 07:25
@ADD-SP
Copy link
Copy Markdown
Member

ADD-SP commented Mar 30, 2026

Hi @Daksh14, are you willing to re-open this PR? Based on #6739 (comment), I think we can continue this work.

@Daksh14 Daksh14 restored the stablize-local-thread branch March 30, 2026 19:15
@Daksh14 Daksh14 reopened this Mar 30, 2026
@Daksh14 Daksh14 force-pushed the stablize-local-thread branch from 4f436e0 to 5f9867f Compare March 30, 2026 19:21
@Daksh14 Daksh14 force-pushed the stablize-local-thread branch from 5f9867f to 958aea4 Compare March 30, 2026 19:22
@Daksh14 Daksh14 marked this pull request as ready for review March 30, 2026 19:22
Comment thread tokio/src/runtime/builder.rs Outdated
Comment thread tokio/Cargo.toml Outdated

[dependencies]
tokio-macros = { version = "~2.6.0", optional = true }
tokio-macros = { path = "../tokio-macros", optional = true }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm expecting that to make this work we should add also the version here, and then add a path dev dependency to Tokio in tokio-macros/Cargo.toml like it was done in this PR. Once we release the new changes we can remove the path deps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the other PR was merged, this is now included here since I merged in master.

Copy link
Copy Markdown
Member

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Darksonn Darksonn enabled auto-merge (squash) April 2, 2026 12:54
@Darksonn Darksonn merged commit 1fc450a into tokio-rs:master Apr 2, 2026
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants