Execute batch of promises in series. Once Promise.all is done go to the next batch
<p>I have an array that contains an array of promises, and each inner array could have either 4k, 2k or 500 promises.</p>

<p>In total there are around 60k promises and I may test it with other values as well.</p>

<p>Now I need to execute the <code>Promise.all(BigArray[0])</code>.</p>

<p>Once the first inner array is done, I need to execute the next <code>Promise.all(BigArray[1])</code> and so on and so on.</p>

<p>If I try to execute a <code>Promise.all(BigArray)</code> it's throwing:</p>

<pre><code>fatal error call_and_retry_2 allocation failed - process out of memory
</code></pre>

<p>I need to execute it each of promises in series, not in parallel which I think that’s what Node its doing. I shouldn't use new libs however am willing to consider the answer!.</p>

<p>Edit:</p>

<p>Here is an example piece of code:</p>

<pre><code>function getInfoForEveryInnerArgument(InnerArray) {
    const CPTPromises = _.map(InnerArray, (argument) =&gt; getDBInfo(argument));
    return Promise.all(CPTPromises)
        .then((results) =&gt; {
            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) =&gt; getInfoForEveryInnerArgument(InnerArray));

    Promise.all(promiseArrayCombination).then((fullResults) =&gt; {
        console.log(fullResults);
        return fullResults;
    })
}
</code></pre>