Skip to content

Instantly share code, notes, and snippets.

@ernestofreyreg
Created February 10, 2020 21:39
Show Gist options
  • Save ernestofreyreg/a2a0463be663c8dbbd1473043ca5753b to your computer and use it in GitHub Desktop.
Save ernestofreyreg/a2a0463be663c8dbbd1473043ca5753b to your computer and use it in GitHub Desktop.
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