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

208
Vistas
Why promise.all crash an error but not sending promises one by one?

I'm pretty new here and I have a problem on my backend nodejs.

I have a list of object that will help me find a car in the database, and so I prepare promises to get data one by one and send that inside a promise.all to trigger the promises.

the function getCar is working every time with data I sent but When I do the promise.all with the array then it will have an error of pool of connection. What is the probleme ?

function requestData (listOfCar) {
    const promiseList = [];

    for (let i = 0; i < listOfCar.length; i++) {
        promiseList.push(getCar(listOfCar[i]));
    }

    return Promise.all(promiseList); // crash but sending promises one by one is working
}

function getCar(carFinder) {
    // do things and return a query find in sequelize to find a car 
    // and so it return a promise
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Promise are always directly trigger, they do not wait to be trigger inside the promise.all. So your problem is that you are sending I guess way to many request inside the database and so the pool of connection do not accept it anymore To fix that you can add more pool of connection or you can simply trigger promise little chunk of 5 and await the promise.all

async function requestData (listOfCar) {
    const carLists = [];

    for (let i = 0; i < listOfCar.length; i++) {
        const tmpListOfPromise = [];
        for (let j = 0; j < 5 && i < listOfCar; j++) {
            const tmpListOfPromise.push(getCar(listOfCar[i]));
            i = i + 1;
        }
        await Promise.all(tmpListOfPromise).then((response) => {
            carLists = carLists.concat(response);  // this will push every response in the list
        });
    }
}

function getCar(carFinder) {
    // do things and return a query find in sequelize to find a car
    // and so it return a promise
}
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