@homeofthings/node-utils
Version:
HomeOfThings - Node Utils: various utilities and common types
21 lines • 654 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wait = wait;
function wait(cond, timeout = 0, intervall = 100) {
return new Promise((resolve, reject) => {
let counter = 0;
const timer = setInterval(() => {
if (cond()) {
clearInterval(timer);
resolve();
return;
}
if (timeout > 0 && ++counter * intervall >= timeout) {
clearInterval(timer);
reject(new Error('timeout reached'));
return;
}
}, intervall);
});
}
//# sourceMappingURL=wait.js.map