MCPcopy
hub / github.com/colbymchenry/codegraph / waitForMessage

Function waitForMessage

__tests__/mcp-roots.test.ts:52–69  ·  view source on GitHub ↗
(
  messages: ReadonlyArray<Record<string, any>>,
  predicate: (m: Record<string, any>) => boolean,
  timeoutMs: number,
)

Source from the content-addressed store, hash-verified

50}
51
52function waitForMessage(
53 messages: ReadonlyArray<Record<string, any>>,
54 predicate: (m: Record<string, any>) => boolean,
55 timeoutMs: number,
56): Promise<Record<string, any>> {
57 return new Promise((resolve, reject) => {
58 const started = Date.now();
59 const tick = () => {
60 const hit = messages.find(predicate);
61 if (hit) return resolve(hit);
62 if (Date.now() - started > timeoutMs) {
63 return reject(new Error(`Timed out. Messages so far: ${JSON.stringify(messages)}`));
64 }
65 setTimeout(tick, 20);
66 };
67 tick();
68 });
69}
70
71function send(child: ChildProcessWithoutNullStreams, msg: object): void {
72 child.stdin.write(JSON.stringify(msg) + '\n');

Callers 1

mcp-roots.test.tsFile · 0.85

Calls 1

tickFunction · 0.70

Tested by

no test coverage detected