That said, it isn't too hard to write re-usable helpers for promise based control flow, in a similar manner to what async.js does for callbacks.
function iff(condition, method) {
return Promise.try(condition).then(result => {
if (result) {
return method();
}
});
}
function whilst(condition, method) {
return iff(condition, () => {
return Promise.try(method)
.then(whilst.bind(null, condition, method));
});
}
whilst(someAsyncAction, Promise.sleep.bind(null, 1000))
.catch(err => {
// ...
})
Naturally you wouldn't want to re-implement all of this control flow every time you need it. But the end result is not too much boilerplate.