consider the following simple code code:
await Promise.all(arrayOfObjects.map(async (obj) => {
return await someAsyncFunctionOnObj(obj);
}));
My problem is, arrayOfObjects, and someAsyncFunctionOnObj, take too much memory while executing, because the loop doesn't wait for the execution to finish, instead it calls someAsyncFunctionOnObj(obj), on each one, and waits till all are resolved, not necessary in order, this causes OOM crash. Iv'e tried using a recursive async function, which does solve the order problem, but still causes OOM crash.
The flow I want to achieve is a synchronous loop, meaning
await someAsyncFunctionOnObj(obj1); // wait for it to finish
await someAsyncFunctionOnObj(obj2); // wait for it to finish
...
Any suggestions on how to correctly implement it?