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

Function waitForMessage

__tests__/mcp-subproject-adoption.test.ts:59–76  ·  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

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

Callers 1

driveStatusCallFunction · 0.70

Calls 1

tickFunction · 0.70

Tested by

no test coverage detected