Re:Ask HN: Why can't await be used from non-async functions?
by Blahah on Monday February 28, 2022 @01:24PM
(#30503143)
when you use `await a`, a is wrapped in a promise. Try returning await a - you get a promise and not the literal. In your example you don't use the promise, and a is a literal.
> async function test() {
}> let b = test()
> console.log(b)
> Promise { 'yep', [Symbol(async_id_symbol)]: 1215, [Symbol(trigger_async_id_symbol)]: 5, [Symbol(destroyed)]: { destroyed: false } }
The promise you create with `await a` resolves immediately (equivalent to Promise.resolve(a)), but it's still a promise.