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

206
Views
JavaScript, detect when a promise in an array of promises is resolved then do something with it

I have the following code :-

      for (let i = 0; i < fdlist.length; i++) {
        let request = fetch(`${domain}/segment?mode=${mode}&type=${type}`,  {    method: 'POST', body: fdlist[i]   }).then((res) => res.json());
        requestlist.push(request)
        console.log(requestlist)
        }
        const allData = Promise.all(requestlist);
        allData.then(async (res) => { 

It sends multiple fetch requests and pushes each one of them to a list, then I do a Promise.all to wait for all of them to resolve and process all the results at once.

My question is, how can I process the promises that resolve right away instead of waiting for all the promises to resolve to begin processing?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

just loop through the promises and add "then" clauses:

for (const p of requestlist) {
  p.then(result => ...)
}

// you can always still wait for them all if you want
Promise.all(requestlist).then(...)

you can add your then at the start when you fetch:


for (...) {
  let request = fetch(...)
  const processed = request.then(response => ...)
  requestlist.push(processed)
}

// wait for it all here if you still want
Promise.all(requestlist).then(...)
about 4 years ago · Santiago Gelvez 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!