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

107
Views
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
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!