So I need to do something like:
promiseFunction1().then((result) => {
}).catch((err) => {
// handle err
});
promiseFunction2().then((result) => {
}).catch((err) => {
// handle err
});
....
promiseFunctionN().then((result) => {
}).catch((err) => {
// handle err
});
// WAIT FOR BOTH PROMISES TO FINISH
functionWhenAllPromisesFinished();
I cannot use Promise.all
, as I DO NOT CARE IF ONE or ALL OF THEM FAIL. I need to be sure that ALL promises have finished. Also, the callback functions in then()
are quite unique to each of the promiseFunctionX()
.
I am sure this is somewhat trivial, but I cannot figure it out. My initial idea was to keep a counter in the upper scope of running promises and incrementing it when one is run and decrementing it in finally()
. Then I would need some async function checkIfRunningPromisesAre0()
, but I am not sure how to implement this either, as it looked like recursion hell.
Here is my sample, but consider it just a material to laugh at poor implementation:
async function RunningPromisesFinished(){
if(RunningPromises > 0){
await sleep(2000);
return await RunningPromisesFinished();
}else{
return true;
}
}
on top of that Id have to implement async function sleep(N)
and in few seconds the recursion level would be high, which im sure is not good for RAM.