Add a loopWhile primitive to Asyc module
This commit is contained in:
parent
a74b0cc480
commit
0e92cf2b05
1 changed files with 11 additions and 0 deletions
|
@ -3,6 +3,7 @@ return {
|
|||
bind: bind,
|
||||
fail: fail,
|
||||
http: http,
|
||||
loopWhile: loopWhile,
|
||||
map: map,
|
||||
parallel: parallel,
|
||||
run: run,
|
||||
|
@ -100,6 +101,16 @@ function sequence() {
|
|||
};
|
||||
}
|
||||
|
||||
function loopWhile(predicate, body) {
|
||||
return bind(predicate, function(keepOn) {
|
||||
if(keepOn) {
|
||||
return sequence(body, loopWhile(predicate, body));
|
||||
} else {
|
||||
return wrap();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function wait(delay) {
|
||||
return function(f) {
|
||||
setTimeout(f, delay);
|
||||
|
|
Loading…
Reference in a new issue