Created
February 10, 2020 21:39
-
-
Save ernestofreyreg/a2a0463be663c8dbbd1473043ca5753b to your computer and use it in GitHub Desktop.
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
const pwhile = function (condition, action) { | |
const loop = function (promise) { | |
if (!condition()) { | |
return promise | |
} | |
return promise | |
.then(action) | |
.then(() => loop(promise)) | |
.catch(promise.reject) | |
} | |
return loop(Promise.resolve()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment