Skip to content

Instantly share code, notes, and snippets.

@colwem
Created April 20, 2016 02:29
Show Gist options
  • Save colwem/b29ebee98bc64d8b43fdcbcef753d454 to your computer and use it in GitHub Desktop.
Save colwem/b29ebee98bc64d8b43fdcbcef753d454 to your computer and use it in GitHub Desktop.
function execute until promise condition fails
function until(fn, condition) {
condition()
.then((met) => {
if(met) {
fn().then(() => {
until(fn, condition);
});
}
});
}
value = 20;
fn = () => {
return Promise.try(() => {
value = value - 1
console.log(value);
});
};
cond = () => Promise.try(() => value > 10);
until(fn, cond);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment