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

111
Vistas
Javascript push and wait for async promises in array

I want to wait for an array of Promises but I cannot add them without executing them. So I had to create a wrapper function, however Promise.all does not execute them.

This is my code:

    const set = new Set(Array.from([1, 2, 3, 4, 5]));

    const func = async (input) => {
        let result = await asyncFunc(input);
        return result;
    }

    var promises = [];
    for(const element of set) {
        promises.push(() => { func(element) });
    }

    await Promise.all(promises).then(values => {
        console.log(values);
    }); 

I exepect Promise.all executes the func function, but it does not. How can I achieve this result?

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

0

You could just push promises to your array, not functions:

    const set = new Set(Array.from([1, 2, 3, 4, 5]));

    const func = async (input) => {
        let result = await asyncFunc(input);
        return result;
    }

    var promises = [];
    for(const element of set) {
        promises.push(func(element));
    }

    await Promise.all(promises).then(values => {
        console.log(values);
    }); 
about 4 years ago · Juan Pablo Isaza Denunciar

0

I found my problem!

The issue of mine was that some of my promises will reject and Promise.all does not continue when this is the case!

I solved by using Promise.allSettled!

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