Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
Resolve multiple network calls at once in react

I want to download time-series data from a rest service. Currently, I have the following implementation

async function getTimeSeriesQuery(i) {
  // Using this to show how gql is being used
  appollo.query(getChunkQueryOptions(i))
}

var promises = []

for(var i = 0; i < numberChunks; i++) {
  promises.push(getTimeSeriesQuery(i))
}
const data = Promise.all(promises)

image.pngImgae of chunked queries

I expected the promises to take the same amount of time as one promise but it seems to scale with the number of promises I have in the list of promises

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The exection time of each promise has nothing to do with number of promises on the list nor with the exection time of another promise.

Promise.all doesn't begin Promises execution, it just waits for them to finish. If all of the Promises already were resolved earlier (for example if all HTTP requests already have finished), then the Promise.all will resolve to a value almost immediately, because there is simply nothing to wait for anymore. Promise.all, gives in a list the results of each promise.

Example : We have a liste of 2 promises : - 1 takes 10s - 2 taked 1s Promise.all will take 10s.

about 4 years ago · Juan Pablo Isaza Report

0

As mentioned, the duration of each request cannot be determined beforehand.

If you want, though, to wait for all to complete, you need to add the promises in your array (which the snippet you posted does not). And if you want the data in a variable, you will need to either use the .then or await for the results.

So you need to return the actual promise from your getTimeSeriesQuery

async function getTimeSeriesQuery(i) {
  // Using this to show how gql is being used
  // was missing the return
  return appollo.query(getChunkQueryOptions(i))
}

var promises = []

for(var i = 0; i < numberChunks; i++) {
  promises.push(getTimeSeriesQuery(i))
}

const data = await Promise.all(promises)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!