tsbase
Version:
Base class libraries for TypeScript
28 lines • 867 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Until = Until;
const tenSeconds = 10000;
/**
* Wait until the condition is met or the given limit is reached (whichever is first).
* @param condition
* @param interval
* @param limit
*/
function Until(condition, interval = 0, limit = tenSeconds) {
return new Promise((resolve) => {
let conditionMet = false;
let elapsedTime = 0;
const enabled = () => !conditionMet && elapsedTime < limit;
const executer = setInterval(async () => {
elapsedTime += (interval || 1);
if (enabled()) {
conditionMet = condition();
}
else {
clearInterval(executer);
resolve(conditionMet);
}
}, interval);
});
}
//# sourceMappingURL=Until.js.map