Top-Level await
has moved to stage 3, so the answer to your question How can I use async/await at the top level? is to just add await
the call to main()
:
async function main() {
var value = await Promise.resolve('Hey there');
console.log('inside: ' + value);
return value;
}
var text = await main();
console.log('outside: ' + text)
Or just:
const text = await Promise.resolve('Hey there');
console.log('outside: ' + text)
--harmony-top-level-await