我有一个包含一系列承诺的数组,每个内部数组可以有 4k、2k 或 500 个承诺。
总共有大约 60k 个 promise,我也可以用其他值对其进行测试。
现在我需要执行Promise.all(BigArray[0])
.
一旦第一个内部数组完成,我需要执行下一个Promise.all(BigArray[1])
等等。
如果我尝试执行Promise.all(BigArray)
它会抛出:
fatal error call_and_retry_2 allocation failed - process out of memory
我需要依次执行每个 Promise,而不是并行执行,我认为这就是 Node 所做的。我不应该使用新的库但是愿意考虑答案!。
编辑:
这是一段示例代码:
function getInfoForEveryInnerArgument(InnerArray) {
const CPTPromises = _.map(InnerArray, (argument) => getDBInfo(argument));
return Promise.all(CPTPromises)
.then((results) => {
return doSomethingWithResults(results);
});
}
function mainFunction() {
BigArray = [[argument1, argument2, argument3, argument4], [argument5, argument6, argument7, argument8], ....];
//the summ of all arguments is over 60k...
const promiseArrayCombination = _.map(BigArray, (InnerArray, key) => getInfoForEveryInnerArgument(InnerArray));
Promise.all(promiseArrayCombination).then((fullResults) => {
console.log(fullResults);
return fullResults;
})
}