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

131
Views
esperar a que finalice la función

Tengo esta función con el mapa, ¿cómo puedo llamar solo cuando termine?

 _.map(data,async function (el) { if(Number.parseInt(el) != NaN && (el != null) && !isNaN(el)){ console.log('ID: ' + el) await scrapeDetails(el) // <--- need to wait finish and than go to next element in map } }) async function scrapeDetails(id){ // ... bla bla }
about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

map y otras funciones de orden superior tienen comportamientos funky cuando se les dan funciones async...await . La mejor solución que encontré hasta ahora es usar la sintaxis for...of con await . Algo como esto:

 for (const element of data) { // do all operations here }
about 4 years ago · Santiago Gelvez Report

0

Recoge las promesas y resuélvelas con Promise.all(). Todos están listos cuando eso está hecho.

 const promises = _.map(data, function (el) { if(Number.parseInt(el) != NaN && (el != null) && !isNaN(el)){ console.log('ID: ' + el) return scrapeDetails(el) } else { return Promise.resolve(); } }); let allResults = await Promise.all(promises); console.log('now we are done!')
about 4 years ago · Santiago Gelvez Report

0

O siempre puedes usar la recursividad.

 const asyncProcess = async (array, index) => { const value = array[index]; if (!value) return; .. await scrapeDetails(el); return asyncProcess(array, index + 1); }
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!