before
await
syntax is only used in async
function.
after
When await
syntax is allowed in normal function, it will be convinient. You don't need more async
functions for values from promise.
function exec() {
const fetched = await fetch('https://es.discourse.group');
console.log(fetched);
}
exec();
ljharb
2
That is by design; await
is mostly sugar for Promises, so you always need one.
There is GitHub - tc39/proposal-async-do-expressions: async `do` expressions for JavaScript
allow you to introduce an asynchronous context within synchronous code without needing an immediately-invoked async function expression.
2 Likes