Consider the following two approaches:
// approach 1
const someFunc = async () => {
const [responseA, responseB] = await Promise.all([
someQuery({ param: 'abc' }),
someQuery({ param: '123' }),
])
return {
responseA,
responseB,
}
}
// approach 2
const someFunc = async () => {
return {
responseA: await someQuery({ param: 'abc' }),
responseB: await someQuery({ param: '123' })
}
}
Would these two approaches respond with the same speed? I presume that the Promise.all
approach would be a bit faster, because it await
s all promises before responding.