I know that the async await
is the new Promise
in the town and it is a new way to write asynchronous code and I also know that
We didn’t ha
Building on unional's answer:
You can achieve the same behavior as Promise.all
with async/await
function foo() {
Promise.all([backend.doSomething(), backend.doAnotherThing()])
.then(([a, b]) => {
return a + b
})
}
async function foo() {
const a = backend.doSomething()
const b = backend.doAnotherThing()
return await a + await b
}
Backend tasks happen concurrently and we wait on both to be finished before we return. See also the MDN example I wrote
Based on this I am not sure if there is any performance advantage to directly using Promises over async/await
.