Skip to content
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

Add option to spawn workers as a module #421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JonasAlaif
Copy link

Workers created with the --target web flag must be spawned as a module. This adds the option to do that, alleviating the current --target no-modules missing features described here. I will create a linked PR in trunk to add an option to create workers with this flag.

Copy link
Collaborator

@futursolo futursolo left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request.

TBH, I am fine with switching to ESModule-only for the Worker implementation since all major browser has support of it, the ESModule adoption for Web Worker is pretty overdue at this point of time.
However, it is also good to have a non-breaking upgrade path so people are not forced to switch immediately.

crates/worker/src/actor/spawner.rs Outdated Show resolved Hide resolved
crates/worker/src/actor/spawner.rs Outdated Show resolved Hide resolved
crates/worker/src/actor/spawner.rs Outdated Show resolved Hide resolved
crates/worker/src/oneshot/spawner.rs Outdated Show resolved Hide resolved
@ranile
Copy link
Collaborator

ranile commented Dec 8, 2023

Every major browser supports it so I don't see the need to keep the no-modules around. There is no user code that needs to be updated, as far as I'm aware, as all the JS is generated by wasm-bindgen and it calls WASM.

@JonasAlaif JonasAlaif force-pushed the spawn-options branch 4 times, most recently from 2b207f1 to 44b25d5 Compare December 8, 2023 16:16
@JonasAlaif
Copy link
Author

I've changed the default to spawn the worker as a module (which means that this will be a breaking change), but I think it's worthwhile keeping the old behavior around for backwards compatibility reasons.

This would allow creating workers with the `--target web` flag, alleviating the current missing features described [here](https://rustwasm.github.io/wasm-bindgen/examples/without-a-bundler.html?highlight=no-modules#using-the-older---target-no-modules)
@JonasAlaif
Copy link
Author

Ready to merge now. Will be a breaking change regardless, since both the public API of spawner is changed as well as the default as_module is changed.

@JonasAlaif
Copy link
Author

@hamza1311 or @futursolo if you have time :)

@JonasAlaif
Copy link
Author

This is ready to be merged @hamza1311 @futursolo

@TaoVonQi
Copy link

I really need this PR. Any timeline when it will be available?

@JonasAlaif
Copy link
Author

@ranile any chance you could have a look at merging this? Hopefully there aren't any conflicts in the meantime

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