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,
|
bind: bind,
|
||||||
fail: fail,
|
fail: fail,
|
||||||
http: http,
|
http: http,
|
||||||
|
loopWhile: loopWhile,
|
||||||
map: map,
|
map: map,
|
||||||
parallel: parallel,
|
parallel: parallel,
|
||||||
run: run,
|
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) {
|
function wait(delay) {
|
||||||
return function(f) {
|
return function(f) {
|
||||||
setTimeout(f, delay);
|
setTimeout(f, delay);
|
||||||
|
|
Loading…
Reference in a new issue