From time to time, I am faced with the problem of having to execute several promises in a fixed order in JavaScript.
Unlike promises that are executed in parallel (via Promise.all()), to my knowledge there is no method for this on the Promise object. So you have to build this functionality yourself.
This is how I solved this problem for myself:
The following was important to me in this solution:
All Promises are wrapped in an anonymous function, so that they are not executed until the previous Promise has been resolved.
As soon as an error occurs and a Promise cannot be resolved, the sequence is stopped, no further Promises are executed and the errors that occurred are propagated.
Leave a comment
Replied on your own website? Send a Webmention!