From 0e92cf2b058d7d75efce23f3d147fa6521290b64 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Wed, 6 Jan 2021 12:32:24 +0100 Subject: [PATCH] Add a loopWhile primitive to Asyc module --- src/UnitJS/Async.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/UnitJS/Async.js b/src/UnitJS/Async.js index 06f1953..c2c8742 100644 --- a/src/UnitJS/Async.js +++ b/src/UnitJS/Async.js @@ -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);