MCPcopy
hub / github.com/MALSync/MALSync / waitUntilTrue

Function waitUntilTrue

src/utils/general.ts:141–162  ·  view source on GitHub ↗
(condition: Function, callback: Function, interval = 200)

Source from the content-addressed store, hash-verified

139}
140
141export function waitUntilTrue(condition: Function, callback: Function, interval = 200) {
142 // eslint-disable-next-line @typescript-eslint/no-misused-promises
143 const intervalId = setInterval(async function () {
144 let state = false;
145 try {
146 const conditionState = condition() as boolean | Promise<boolean>;
147 if (conditionState && conditionState instanceof Promise) {
148 state = await conditionState;
149 } else {
150 state = conditionState;
151 }
152 } catch (e) {
153 con.info('Error in waitUntilTrue', e);
154 }
155 if (state) {
156 clearInterval(intervalId);
157 callback();
158 }
159 }, interval);
160
161 return intervalId;
162}
163
164export function getAsyncWaitUntilTrue(condition: Function, interval = 100) {
165 let intervalId;

Callers 1

getAsyncWaitUntilTrueFunction · 0.85

Calls 3

conditionFunction · 0.85
callbackClass · 0.50
infoMethod · 0.45

Tested by

no test coverage detected