Last active
August 19, 2016 20:21
-
-
Save akhoury/a7023f149fcb173ae3616b61b677a938 to your computer and use it in GitHub Desktop.
promiseWhile()
This file contains hidden or 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 promiseWhile (condition, execute) { | |
return new Promise(function(resolve, reject) { | |
var iterate = function () { | |
if (condition()) { | |
return execute() | |
.then(iterate) | |
.catch(reject); | |
} | |
return resolve(); | |
}; | |
return iterate(); | |
}); | |
} | |
module.exports = promiseWhile; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment