There are some similar questions about bluebird, jQuery, and Q deferreds and promises but those libraries have some subtle differences to the new, standard, built-in promises that came to JavaScript in the ES6 standard.
I'd like a nice canonical answer for how best to idiomatically code the various kinds of conditional looping constructs serially. That is, when the next iteration is only asynchronously initiated once the previous one asynchronously completed, and when the entire sequence is terminated when some condition is met, as with a do
, for
, while
loop, etc.
I find the parallel and non conditional equivalents are easy and intuitive whereas many of us have trouble when we need loops which are conditional, serial, and asynchronous at once.
I'm not sure whether serial loops where the result of one operation is the input to the next require different idioms to serial loops done for other reasons, such as conserving resources or imposed by web APIs.