0

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 awaits all promises before responding.

Mike K
  • 7,621
  • 14
  • 60
  • 120
  • The first example doesn't return an `Array`, if that's what you're implying. `ResponseA` and `responseB` are both objects, and `someFunc` returns an `Object` of objects. – Mike K Feb 07 '22 at 08:22
  • 1
    Approach 2 waits for the result.of the first query before it starts the second query. – jabaa Feb 07 '22 at 08:27

0 Answers0