Created
April 20, 2016 02:29
-
-
Save colwem/b29ebee98bc64d8b43fdcbcef753d454 to your computer and use it in GitHub Desktop.
function execute until promise condition fails
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 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