MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / waitFor

Function waitFor

packages/server/test/ws-terminal.e2e.test.ts:142–162  ·  view source on GitHub ↗
(
  received: Record<string, unknown>[],
  pred: (frame: Record<string, unknown>) => boolean,
  timeoutMs = 2000,
)

Source from the content-addressed store, hash-verified

140}
141
142async function waitFor(
143 received: Record<string, unknown>[],
144 pred: (frame: Record<string, unknown>) => boolean,
145 timeoutMs = 2000,
146): Promise<Record<string, unknown>> {
147 const start = Date.now();
148 while (Date.now() - start < timeoutMs) {
149 const hit = received.find(pred);
150 if (hit !== undefined) return hit;
151 await new Promise((resolve) => setTimeout(resolve, 10));
152 }
153 throw new Error(
154 `waitFor timed out; received: ${received
155 .map((frame) => {
156 const frameType = typeof frame['type'] === 'string' ? frame['type'] : '(unknown)';
157 const frameId = typeof frame['id'] === 'string' ? frame['id'] : '';
158 return `${frameType}:${frameId}`;
159 })
160 .join(', ')}`,
161 );
162}
163
164describe('terminal WS controls', () => {
165 it('attaches, replays output, forwards live output, input, resize, and close', async () => {

Callers 2

openSocketFunction · 0.70

Calls 1

nowMethod · 0.65

Tested by

no test coverage detected