Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Oct 23, 2021
1 parent 426501f commit 67f78d1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 35 deletions.
45 changes: 28 additions & 17 deletions dist/es/wait-until.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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();
});
}
45 changes: 28 additions & 17 deletions dist/lib/wait-until.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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();
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 67f78d1

Please sign in to comment.