From 67f78d17fdf32614cea0d28a7995e4f9b112f0c6 Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Sat, 23 Oct 2021 19:31:44 +0200 Subject: [PATCH] 2.0.0 --- dist/es/wait-until.js | 45 ++++++++++++++++++++++++++---------------- dist/lib/wait-until.js | 45 ++++++++++++++++++++++++++---------------- package.json | 2 +- 3 files changed, 57 insertions(+), 35 deletions(-) diff --git a/dist/es/wait-until.js b/dist/es/wait-until.js index 0e979cc..9c5a697 100644 --- a/dist/es/wait-until.js +++ b/dist/es/wait-until.js @@ -13,28 +13,39 @@ export default function waitUntil(fun) { var timedOut = false; var ok = false; - if (timeout !== 0) wait(timeout).then(function () { - return timedOut = true; - }); + if (timeout !== 0) { + wait(timeout).then(function () { + return timedOut = true; + }); + } return new Promise(function (resolve, reject) { - var runLoop = function runLoop() { + + /** + * @recursive + * @return {Promise} + */ + function runLoopOnce() { if (ok) { resolve(); - return; - } - if (timedOut) { + } else if (timedOut) { reject(new Error('AsyncTestUtil.waitUntil(): reached timeout of ' + timeout + 'ms')); - return; - } - wait(interval).then(function () { - var value = promisify(fun()); - value.then(function (val) { - ok = val; - runLoop(); + } else { + return wait(interval).then(function () { + return promisify(fun()); + }) + /** + * Propagate errors of the fun function + * upwards. + */ + ['catch'](function (err) { + return reject(err); + }).then(function (value) { + ok = value; + return runLoopOnce(); }); - }); - }; - runLoop(); + } + } + runLoopOnce(); }); } \ No newline at end of file diff --git a/dist/lib/wait-until.js b/dist/lib/wait-until.js index 0b28942..b18dff7 100644 --- a/dist/lib/wait-until.js +++ b/dist/lib/wait-until.js @@ -27,28 +27,39 @@ function waitUntil(fun) { var timedOut = false; var ok = false; - if (timeout !== 0) (0, _wait2['default'])(timeout).then(function () { - return timedOut = true; - }); + if (timeout !== 0) { + (0, _wait2['default'])(timeout).then(function () { + return timedOut = true; + }); + } return new Promise(function (resolve, reject) { - var runLoop = function runLoop() { + + /** + * @recursive + * @return {Promise} + */ + function runLoopOnce() { if (ok) { resolve(); - return; - } - if (timedOut) { + } else if (timedOut) { reject(new Error('AsyncTestUtil.waitUntil(): reached timeout of ' + timeout + 'ms')); - return; - } - (0, _wait2['default'])(interval).then(function () { - var value = (0, _promisify2['default'])(fun()); - value.then(function (val) { - ok = val; - runLoop(); + } else { + return (0, _wait2['default'])(interval).then(function () { + return (0, _promisify2['default'])(fun()); + }) + /** + * Propagate errors of the fun function + * upwards. + */ + ['catch'](function (err) { + return reject(err); + }).then(function (value) { + ok = value; + return runLoopOnce(); }); - }); - }; - runLoop(); + } + } + runLoopOnce(); }); } \ No newline at end of file diff --git a/package.json b/package.json index f591189..d271fe1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "async-test-util", - "version": "1.7.3", + "version": "2.0.0", "description": "Util-functions that are be useful in async tests", "keywords": [ "async",