Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

274
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda