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

Function waitForEvent

packages/node-sdk/test/session-prompt-events.test.ts:433–451  ·  view source on GitHub ↗
(
  session: {
    onEvent(listener: (event: Event) => void): () => void;
  },
  predicate: (event: Event) => boolean,
)

Source from the content-addressed store, hash-verified

431}
432
433function waitForEvent(
434 session: {
435 onEvent(listener: (event: Event) => void): () => void;
436 },
437 predicate: (event: Event) => boolean,
438): Promise<Event> {
439 return new Promise((resolve, reject) => {
440 const timeout = setTimeout(() => {
441 unsubscribe();
442 reject(new Error('Timed out waiting for session event'));
443 }, 1_000);
444 const unsubscribe = session.onEvent((event) => {
445 if (!predicate(event)) return;
446 clearTimeout(timeout);
447 unsubscribe();
448 resolve(event);
449 });
450 });
451}

Callers 1

Calls 3

rejectFunction · 0.85
onEventMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected