That last example is pretty bad imo. Depending on what you want to achieve. If it needs to be sequential, fair enough. At the same time, error handling / retries are a massive pain.
Better would be something like this:
let itemIDs = [1, 2, 3, 4, 5];
const deletions = itemIDs.map(api.deleteItem);
Promise.allSetteled(deletions)
.then()
Then you don't have the dependency on the finish of the last promise (possibly parallelizable) and you will have full control over the results, redoing if wanted
That last example is pretty bad imo. Depending on what you want to achieve. If it needs to be sequential, fair enough. At the same time, error handling / retries are a massive pain. Better would be something like this:
let itemIDs = [1, 2, 3, 4, 5]; const deletions = itemIDs.map(api.deleteItem); Promise.allSetteled(deletions) .then() //<-- Do stuff with result, getting an array of 'fulfilled' or 'rejected'Then you don't have the dependency on the finish of the last promise (possibly parallelizable) and you will have full control over the results, redoing if wanted