The default behavior of Promise.all
is to fail-fast
which means that as soon as one of your promises fails then your entire promise chain stops. This is not always the wanted behavior. For example if you are calling an API endpoint to get data on multiple objects then you want to keep going even if some of them fail. Then you can write your own logic to handle those failures in your Promise.all
resolution.
The related code here runs a function called resob
or resolve object
where it forces a promise to fully resolve with either the result or an error. This allows the Promise.all
to continue to run even though that one request failed.
It's a simple but elegant way to get results for all objects even though request #2 of 200 failed.
Enjoy! shadowcodex
I adapted the above
resob
method to handle callback style methods as well.