Created
August 8, 2017 04:11
-
-
Save jacoscaz/f8215d4bfcb968471ca2bd3cc6c857f6 to your computer and use it in GitHub Desktop.
Promise-based while
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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