Skip to content

Instantly share code, notes, and snippets.

@jacoscaz
Created August 8, 2017 04:11
Show Gist options
  • Save jacoscaz/f8215d4bfcb968471ca2bd3cc6c857f6 to your computer and use it in GitHub Desktop.
Save jacoscaz/f8215d4bfcb968471ca2bd3cc6c857f6 to your computer and use it in GitHub Desktop.
Promise-based while
function whilst(condition, action) {
return P.resolve(condition())
.then(function (proceed) {
if (!proceed) return null;
return P.resolve(action())
.then(function () {
return whilst(condition, action);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment