I'm a fan of Open Source and have a growing interest in serverless and edge computing. I'm not a big fan of spiders, but they're doing good work eating bugs. I also stream on Twitch.
top-level `await` proposal for ECMAScript (stage 3)
ECMAScript proposal: Top-level await
Champion: Myles Borins
Status: Stage 3
Synopsis
Top-level await enables modules to act as big async functions: With top-level await, ECMAScript Modules (ESM) can await resources, causing other modules who import them to wait before they start evaluating their body.
Motivation
Limitations on IIAFEs
With await only available within async functions, a module can include an await in the code that executes at startup by factoring that code into an async function:
Thanks for the post Yaser!
One thing I'd add is that although we don't have top-level await, it's most likely going to happen as it's at Stage 3.
tc39 / proposal-top-level-await
top-level `await` proposal for ECMAScript (stage 3)
ECMAScript proposal: Top-level
await
Champion: Myles Borins
Status: Stage 3
Synopsis
Top-level
await
enables modules to act as big async functions: With top-levelawait
, ECMAScript Modules (ESM) canawait
resources, causing other modules whoimport
them to wait before they start evaluating their body.Motivation
Limitations on IIAFEs
With
await
only available withinasync
functions, a module can include anawait
in the code that executes at startup by factoring that code into anasync
function:This pattern can also be immediately invoked. You could call this an Immediately Invoked Async Function Expression (IIAFE), as a play on IIFE idiom.
Thanks for sharing, didn't know about this 👌🏽
Updated the post to reflect this, thanks again Nick