我有一个包含许多 Promise 的数组,每个内部数组都可能包含 4,000、2,000 或 500 个 Promise。
总共大约有 60,000 个 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;
})
}
Promise.all()
那样并行执行。 - Evan Bechtol