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

130
Views
Cómo esperar a todos en Javascript

Mi código casi funciona bien, mi problema es que solo se registran los primeros datos CSV y finaliza la función lambda.

Supongo que de alguna manera necesito esperar a que terminen todas las stream pipes .

 myCsvList.forEach((myElem) => { const data = []; // setup params const csvFile = s3.getObject(params).createReadStream(); // works fine csvFile .pipe(csv()) .on('data', function(entry) { data.push(entry); }) .on('end', () => { console.log(data); // after the log of the first element on myCsvList, the code finishes. It should log all csvFiles from myCsvList }); });

¿Supongo que necesito una promesa o algo así?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

puede cambiar cada elemento a Promise, luego use Promise.all() :

 const getItem = (myElem) => { const data = []; // setup params const csvFile = s3.getObject(params).createReadStream(); // works fine return new Promise((resolve) => { csvFile .pipe(csv()) .on('data', function (entry) { data.push(entry); }) .on('end', () => { resolve(data); // after the log of the first element on myCsvList, the code finishes. It should log all csvFiles from myCsvList }); }); }; const start = () => { // all promises have been finished return Promise.all(myCsvList.map(myElem => getItem(myElem))); }

myCsvList.map(myElem => getItem(myElem)) puede obtener una lista de promesas, cuando todas las promesas se hayan resuelto, activará Promise.all().

about 4 years ago · Juan Pablo Isaza 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!