MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / waitFor

Function waitFor

__tests__/mcp-daemon.test.ts:119–135  ·  view source on GitHub ↗
(
  predicate: () => T | undefined | null | false,
  timeoutMs: number,
  pollMs = 25,
)

Source from the content-addressed store, hash-verified

117}
118
119function waitFor<T>(
120 predicate: () => T | undefined | null | false,
121 timeoutMs: number,
122 pollMs = 25,
123): Promise<T> {
124 return new Promise((resolve, reject) => {
125 const started = Date.now();
126 const tick = () => {
127 let v: T | undefined | null | false;
128 try { v = predicate(); } catch (e) { return reject(e); }
129 if (v) return resolve(v as T);
130 if (Date.now() - started > timeoutMs) return reject(new Error(`Timed out after ${timeoutMs}ms`));
131 setTimeout(tick, pollMs);
132 };
133 tick();
134 });
135}
136
137function isAlive(pid: number): boolean {
138 try { process.kill(pid, 0); return true; } catch { return false; }

Callers 2

waitProcessExitFunction · 0.70
mcp-daemon.test.tsFile · 0.70

Calls 1

tickFunction · 0.70

Tested by

no test coverage detected