Skip to content

Conversation

@Frando
Copy link
Member

@Frando Frando commented Nov 3, 2025

Description

Mirrors the tokio method. Is a simple alias to spawn because on wasm all tasks are local.

Breaking Changes

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/n0-future/pr/16/docs/n0_watcher/

Last updated: 2025-11-03T12:52:27Z

@Frando Frando requested a review from matheus23 November 3, 2025 12:52
///
/// Mirrors [`tokio::JoinSet::spawn_local](https://docs.rs/tokio/latest/tokio/task/struct.JoinSet.html#method.spawn_local).
/// Because all tasks in WebAssembly are local, this is a simple alias to [`Self::spawn`].
pub fn spawn_local(&mut self, fut: impl IntoFuture<Output = T> + 'static) -> AbortHandle
Copy link
Contributor

Choose a reason for hiding this comment

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

what about the non wasm case? this seems to not be exported

Copy link
Member

Choose a reason for hiding this comment

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

Yeah... I think this might need a

#[cfg(not(wasm_browser))]
pub use tokio::spawn_local;

At the top.

That said, tokio::task::spawn_local can only be used with tokio's LocalSet and LocalRuntime.
We don't have equivalents to these in Wasm in n0_future. So I don't understand how code could be made to "look the same" in Wasm and native with this.

Copy link
Member Author

@Frando Frando Nov 3, 2025

Choose a reason for hiding this comment

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

in the non-wasm case this all maps to tokio::task::JoinSet. The whole module is only enabled with #[cfg(wasm_browser)]

Copy link
Member

Choose a reason for hiding this comment

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

Ah I'm sorry this is inside JoinSet, not the top-level task module!

Copy link
Member

Choose a reason for hiding this comment

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

I'm still confused why we we'd use JoinSet::spawn_local in Wasm/native "polymorphic" code, but yeah this change is definitely not incomplete.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well I have a place in iroh-docs that uses JoinSet with spawn_local, and it was easier to refactor this to not run on a separate thread in wasm but keep the rest of the code identical.

Copy link
Member

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

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

it was easier to refactor this to not run on a separate thread in wasm but keep the rest of the code identical.

I should've assumed this way was the easier way for you.

This crate is meant to make this easier, and this is a straightforward change. Looking good :)

@Frando Frando merged commit 0704b54 into main Nov 3, 2025
30 checks passed
@matheus23 matheus23 deleted the Frando/spawn-local branch November 3, 2025 16:22
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.

4 participants