MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / waitFor

Function waitFor

__tests__/daemon-older-version.test.ts:367–379  ·  view source on GitHub ↗
(predicate: () => T | undefined | null | false, timeoutMs: number, label: string)

Source from the content-addressed store, hash-verified

365}
366
367function waitFor<T>(predicate: () => T | undefined | null | false, timeoutMs: number, label: string): Promise<T> {
368 return new Promise((resolve, reject) => {
369 const started = Date.now();
370 const tick = (): void => {
371 let value: T | undefined | null | false;
372 try { value = predicate(); } catch (e) { reject(e); return; }
373 if (value) { resolve(value as T); return; }
374 if (Date.now() - started > timeoutMs) { reject(new Error(`Timed out after ${timeoutMs}ms waiting for: ${label}`)); return; }
375 setTimeout(tick, 25);
376 };
377 tick();
378 });
379}
380
381function isAlive(pid: number): boolean {
382 try { process.kill(pid, 0); return true; } catch { return false; }

Callers 4

waitProcessExitFunction · 0.70
statusFunction · 0.70
sessionWithDaemonFunction · 0.70

Calls 1

tickFunction · 0.70

Tested by

no test coverage detected