Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
How to await promise function inside nested maps?

Suppose I have the following:

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));
}

How do I await for all the promises inside the second map to resolve? If it was only one map, I could do Promise.all, but promise all is not recursive.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You will need 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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda