Skip to content Skip to sidebar Skip to footer

Express - Promise Pending When Loop Queries

I receive an array with several data and i have to make a query for each element of array. But this was give me a promise pending. How ca i solve that? What is the problem?

Solution 1:

Promise.all takes an array of promises, which parts already is, not an array of arrays of promises ([parts]). Use

returnPromise.all( parts ).then//                 ^     ^

Solution 2:

.then returns a promise so you need do stuff in the .then and not return it.

Promise.all([parts]).then(listOfResults => {
  res.send(JSON.stringify(listOfResults)) //for example
}, err => {
  res.send(500, JSON.stringify(err)); // for example
});

Post a Comment for "Express - Promise Pending When Loop Queries"