Add a loopWhile primitive to Asyc module

This commit is contained in:
Tissevert 2021-01-06 12:32:24 +01:00
parent a74b0cc480
commit 0e92cf2b05

View file

@ -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);