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.
top-level `await` proposal for ECMAScript (stage 3)
ECMAScript proposal: Top-level
awaitChampion: Myles Borins
Status: Stage 3
Synopsis
Top-level
awaitenables modules to act as big async functions: With top-levelawait, ECMAScript Modules (ESM) canawaitresources, causing other modules whoimportthem to wait before they start evaluating their body.Motivation
Limitations on IIAFEs
With
awaitonly available withinasyncfunctions, a module can include anawaitin the code that executes at startup by factoring that code into anasyncfunction: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