Re:Playground Wisdom: Threads Beat Async/Await
by akira2501 on Friday November 22, 2024 @10:28PM
(#42219003)
> Why can't I await in a normal function?
You can. promise.then(callback). If you want the rest of your logic to be "blocking" then the rest of it goes in the callback. the 'then' method itself returns a promise, so you can return that from a non async function, if you like.
> why can't I launch multiple async functions, then await on each of them, in a non-async function that does not return a promise?
Typically? Exception handling semantics. See the difference between Promise.race, Promise.all and Promise.allSettled.
You can. promise.then(callback). If you want the rest of your logic to be "blocking" then the rest of it goes in the callback. the 'then' method itself returns a promise, so you can return that from a non async function, if you like.
> why can't I launch multiple async functions, then await on each of them, in a non-async function that does not return a promise?
Typically? Exception handling semantics. See the difference between Promise.race, Promise.all and Promise.allSettled.