qcobjects
Version:
QCObjects is an Open-source framework that empowers full-stack developers to make micro-services and micro-frontends into an N-Tier architecture.
27 lines (25 loc) • 817 B
text/typescript
import { logger } from "./Logger";
export const waitUntil = (func:()=>void, exp:()=>any):void => {
const _waitUntil = (func:()=>void, exp:()=>any):void => {
const maxWaitCycles = 2000;
let _w = 0;
var _t = setInterval(function () {
if (exp()) {
clearInterval(_t);
func();
logger.debug("Ejecuting " + func.name + " after wait");
} else {
if (_w < maxWaitCycles) {
_w += 1;
logger.debug("WAIT UNTIL " + func.name + " is true, " + _w.toString() + " cycles");
} else {
logger.debug("Max execution time for " + func.name + " expression until true");
clearInterval(_t);
}
}
}, 1);
};
setTimeout(function () {
_waitUntil(func, exp);
}, 1);
};