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

Automatically start main on import. #1939

Open
daxpedda opened this issue Jan 3, 2020 · 1 comment
Open

Automatically start main on import. #1939

daxpedda opened this issue Jan 3, 2020 · 1 comment

Comments

@daxpedda
Copy link
Collaborator

daxpedda commented Jan 3, 2020

Motivation

Especially after #1843, I think it would make a lot of sense that on importing the js file, it would immediately start init and therefore execute main.

This would solve a couple of issues:

  • Less boilerplate: <script src="wasm.js" type="module"></script> would be enough.
    • No need to call init.
    • No need to preload the js file (the wasm still needs to be preloaded).
  • Can be directly used with Worker, because it starts itself.
  • It should only start itself when main or wasm_bindgen(start) is used in rust, which should be pretty intuitive.
  • Behaving like other output modes, bundler and nodejs already do that.

Proposed Solution

Call init after its definition if needs_manual_start is true in cli-support.
Additionally we should add a flag to disable this functionality.

Alternatives

  • Potentially we could always call init to start loading the wasm file, even if there is no start function.
  • Hide this functionality behind a flag instead of making it default and disabling it by a flag.

Additional Context

I am afraid there was some reason that this functionality wasn't implemented already, I just can't figure out why.

EDIT: Just started to implement this when I found the other output modes already do that, only no-modules and web don't.

@daxpedda
Copy link
Collaborator Author

According to @alexcrichton's recommendation (#1940 (comment)) we should wait until ES module integration is out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant