bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Make `Task`s functional on WASM

Open joseph-gio opened this issue 1 year ago • 4 comments

Objective

Right not bevy's task pool abstraction is kind of useless on wasm, since it returns a FakeTask which can't be interacted with. This is only good for fire-and-forget it tasks, and isn't even that useful since it's just a thin wrapper around wasm-bindgen-futures::spawn_local

Solution

Add a simple Task<T> handler type to wasm targets that allow waiting for a task's output or periodically checking for its completion. This PR aims to give the wasm version of these tasks feature parity with the native, multi-threaded version of the task

Testing

  • Did you test these changes? Not yet

joseph-gio avatar Jun 17 '24 04:06 joseph-gio

@kettle11 can I get your review here please?

alice-i-cecile avatar Jun 17 '24 12:06 alice-i-cecile

I don't agree that this is contentious, it's just finishing an incomplete feature. The considerations here are in terms of implementation details, not direction IMO

joseph-gio avatar Jun 17 '24 16:06 joseph-gio

This conceptually looks fine to me, but @JoJoJet have you checked that this still runs with the atomics flag enabled?

This PR has instructions for how to build with that enabled: https://github.com/bevyengine/bevy/pull/12205

That PR enabled Bevy Wasm to compile with threading enabled and make use of other libraries to spawn threads, parallelize, etc. even if Bevy Wasm itself isn't yet threaded internally.

kettle11 avatar Jun 17 '24 20:06 kettle11

I haven't tested that functionality yet but I see no reason it would stop working. I'm hoping that with this PR, full multi-threading support will just be a drop-in addition that utilizes this same interface

joseph-gio avatar Jun 17 '24 21:06 joseph-gio

Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to https://github.com/bevyengine/bevy-website/issues/1660 if you'd like to help out.

alice-i-cecile avatar Oct 20 '24 14:10 alice-i-cecile