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

103
Vistas
JavaScript calling async function at the same time with different parameters

I have an async function “getResults” that performs fetch await, waits for result, then does something with the result.

If I call that async function “getResults” with 2 different parameters at the same time, wanting to fetch 2 different things, it will go ahead and perform only one of them (I guess the one that came in first)

async function getResults(id, source, destination) {
  let result1 = await fetch.listen({
    listen: id
  }, apiHost("api.gps.com", "someparam", source)) /* this would be fetch result with parameters from getLosAngelesRoute function */

  let result2 = /* here I would like to fetch with parameters from getWashingtonRoute function */
  if (result1 !== result2) {
      // do something
    }
  else {
    // do nothing
  }
}

function getLosAngelesRoute() {
  getResults("id1", "newYork", "losAngeles")
}

function getWashingtonRoute() {
  getResults("id2", "detroit", "washington")
}

The workaround fix is to have 2 different functions “getResultsA” and “getResultsB” and call them separately...

But is it possible to call function “getResults” with different parameters from functions getLosAngelesRoute and getWashingtonRoute at the same time, have it fetch await BOTH and then do something with both results all within one function?

Hope this makes sense.

Thank you for your valuable thoughts.

about 4 years ago · Santiago Gelvez
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