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

Top level await #5

Closed
littledan opened this issue Feb 16, 2019 · 8 comments
Closed

Top level await #5

littledan opened this issue Feb 16, 2019 · 8 comments

Comments

@littledan
Copy link

Would it make sense to implement top-level await within this project? It can be accurately simulated by exporting a Promise from each module, and waiting on Promise.all of these exports.

@guybedford
Copy link
Owner

@littledan yes that is not only useful, but necessary to fix the WASM 4KB limit as well.

I'd be keen to work on this if top-level await is looking likely to proceed.

@guybedford
Copy link
Owner

See #1 (comment).

@littledan
Copy link
Author

I hope we can clarify things soon, e.g., at an upcoming TC39 meeting. In theory, Stage 2 should mean it's eventually coming, though.

@guybedford
Copy link
Owner

guybedford commented Aug 21, 2019

I've been putting some thought to how this might be implemented.

Proposed outline:

  • We can detect the use of top-level await based on the "await" keyword being seen at the top-level. Supporting "await" within blocks would require a knowledge of functions v blocks, but that should be straightforward to handle too.
  • When a source has top-level await, we know where all the import and export statements start and end so we could hoist them all up to the top of the source together. class / function / variable default expressions would need to be converted into their non-export form in this process, with some careful handling of these cases.
  • The remaining body can then be wrapped in an async wrapper, with the execution exported as a special unique export name (like __$$tla or something).
  • the rest of the process is then just handling the TLA algorithm

The above would be a comprehensive and fast top-level await polyfill!

I don't have the resources to work on this right now, but if anyone would like to push things forward I'd be very open to either helping a contributor or to sponsorship of my time to implement this feature.

@MathiasWP
Copy link
Contributor

Any updates on this issue?

@guybedford
Copy link
Owner

None currently but it remains a core part of the roadmap of this project. The problem is just one of prioritization.

@trusktr
Copy link

trusktr commented Feb 16, 2022

No one mentioned it, but just in case, Node.js already has built-in top-level await, as well as all browsers. 🎉

@guybedford
Copy link
Owner

Top-level await was shipped so quickly by browsers that it has ended up not being a problem for this project.

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

No branches or pull requests

4 participants