In a video I watch from the NodeJS conventions, there is a trap.
Actually, promise.all works well in case of everything being successful.
If one promise fails, the other promises continue running and if they fail too, boom!
This is a good point. In this case, you would want to make sure that the async functions you're calling (e.g. GetAllStates()) are catching and handling their own errors. Another option is to use Promise.allSettled() which will return objects that have a status of 'fulfilled' or 'rejected' and either a value (the return value of the function) or a reason (the error message) if rejected.
The promises continue running in any case if you have multiple of them pending, regardless of the mechanism you use. (You have to pass around an abort token or the like to cancel execution in that case, and check it through the execution of the async functions being called, to deal with that case.)
Promise.all() does hook rejection on all of them, though admittedly it does swallow the other errors if any of the others fail as well. Sequential await will leave you with unhandled rejections, though, if an earlier promise in the sequence rejects.
In a video I watch from the NodeJS conventions, there is a trap.
Actually, promise.all works well in case of everything being successful.
If one promise fails, the other promises continue running and if they fail too, boom!
This is a good point. In this case, you would want to make sure that the async functions you're calling (e.g. GetAllStates()) are catching and handling their own errors. Another option is to use Promise.allSettled() which will return objects that have a status of 'fulfilled' or 'rejected' and either a value (the return value of the function) or a reason (the error message) if rejected.
The promises continue running in any case if you have multiple of them pending, regardless of the mechanism you use. (You have to pass around an abort token or the like to cancel execution in that case, and check it through the execution of the async functions being called, to deal with that case.)
Promise.all()
does hook rejection on all of them, though admittedly it does swallow the other errors if any of the others fail as well. Sequentialawait
will leave you with unhandled rejections, though, if an earlier promise in the sequence rejects.That is true