-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add JoinSet::spawn_local #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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 |
| /// | ||
| /// 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)]
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
matheus23
left a comment
There was a problem hiding this 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 :)
Description
Mirrors the tokio method. Is a simple alias to
spawnbecause on wasm all tasks are local.Breaking Changes
Notes & open questions
Change checklist