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

149
Views
Cómo actualizar la lista en el bloque catch

Tengo un pequeño polyfill personalizado para Promise.all y, al intentar ejecutarlo, veo que la actualización de la matriz (lista de errores) en el bloque catch no funciona. ¿Alguien puede ayudarme a entender lo que me estoy perdiendo?

 Promise.customAll = function (promisesList) { let errorList = []; let resultList = []; return new Promise((resolve, reject) => { promisesList.forEach(async (promise, index) => { try { let result = await promise; resultList[index] = (result); } catch (err) { errorList.push(err); } }); if (errorList.length) { reject(errorList); } else { resolve(resultList); } }); };

Así es como lo estoy usando. Para el código anterior, espero que mi promesa tp vaya al bloque de captura, pero luego bloqueará e imprimirá [ 'FirstPromise', <1 empty item>, '3rd Promise' ]

 Promise.customAll([Promise.resolve("FirstPromise"), Promise.reject("Error in 2nd Promise"), Promise.resolve("3rd Promise")]) .then((val) => { console.log(val); }) .catch((err) => { console.log(err); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Promise.customAll = function (promisesList) { let errorList = []; let resultList = []; return new Promise((resolve, reject) => { promisesList.forEach(async (promise, index) => { try { let result = await promise; resultList[index] = result; if (index === promisesList.length - 1) { if (errorList.length) { reject(errorList); } else { resolve(resultList); } } } catch (err) { errorList.push(err); } }); }); };

Según lo sugerido por @youdateme, moví mi lógica en cada devolución de llamada como asíncrono que resolvió el problema.

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!