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

Function waitFor

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

Source from the content-addressed store, hash-verified

126}
127
128function waitFor<T>(
129 predicate: () => T | undefined | null | false,
130 timeoutMs: number,
131 pollMs = 25,
132 label = '',
133): Promise<T> {
134 return new Promise((resolve, reject) => {
135 const started = Date.now();
136 const tick = () => {
137 let v: T | undefined | null | false;
138 try { v = predicate(); } catch (e) { return reject(e); }
139 if (v) return resolve(v as T);
140 if (Date.now() - started > timeoutMs) {
141 // Name the wait: an async stack loses the await site, so an unlabeled
142 // timeout can't tell WHICH step flaked (the #662 test's recurring
143 // timeout was undiagnosable for exactly this reason).
144 return reject(new Error(`Timed out after ${timeoutMs}ms${label ? ` waiting for: ${label}` : ''}`));
145 }
146 setTimeout(tick, pollMs);
147 };
148 tick();
149 });
150}
151
152function isAlive(pid: number): boolean {
153 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