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