Skip to content

Conversation

Daksh14
Copy link
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 6 times, most recently from b220a35 to 53cb390 Compare August 29, 2025 07:11
@Daksh14 Daksh14 force-pushed the stablize-local-thread branch 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
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
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
Contributor

Relevant to this: #6741

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

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);
/// }
/// ```

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.

4 participants