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

153
Views
¿Cómo esperar la función de promesa dentro de los mapas anidados?

Supongamos que tengo lo siguiente:

 async function getReactionScores(userReactions) { const reactionsWithSharesPromises = userReactions.map((reactions) => { return { emoji: reactions.emoji, shares: reactions.users.map(async (user) => { return { username: user.username, // Just as an example of something to wait for shares: await sleep(1, user.id), }; }), }; }); } function sleep(time, userID) { return new Promise((resolve) => setTimeout(resolve(userID), time)); }

¿Cómo espero que se resuelvan todas las promesas dentro del segundo mapa? Si fuera solo un mapa, podría hacer Promise.all, pero Promise all no es recursivo.

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

0

Necesitarás 2 Promise.all

 async function getReactionScores(userReactions) { const reactionsWithSharesPromises = await Promise.all(userReactions.map(async (reactions) => { return { emoji: reactions.emoji, shares: await Promise.all(reactions.users.map(async (user) => { return { username: user.username, // Just as an example of something to wait for shares: await sleep(1, user.id), }; })), }; })); }
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!