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

Function waitForSDKEvent

packages/node-sdk/test/session-runtime-helpers.ts:54–73  ·  view source on GitHub ↗
(
  session: {
    onEvent(listener: (event: Event) => void): () => void;
  },
  predicate: (event: Event) => boolean,
  timeoutMs = 1_000,
)

Source from the content-addressed store, hash-verified

52}
53
54export function waitForSDKEvent(
55 session: {
56 onEvent(listener: (event: Event) => void): () => void;
57 },
58 predicate: (event: Event) => boolean,
59 timeoutMs = 1_000,
60): Promise<Event> {
61 return new Promise((resolve, reject) => {
62 const timeout = setTimeout(() => {
63 unsubscribe();
64 reject(new Error('Timed out waiting for session event'));
65 }, timeoutMs);
66 const unsubscribe = session.onEvent((event) => {
67 if (!predicate(event)) return;
68 clearTimeout(timeout);
69 unsubscribe();
70 resolve(event);
71 });
72 });
73}
74
75async function readWireEvents(homeDir: string, sessionId: string): Promise<readonly unknown[]> {
76 const sessionDir = await readIndexedSessionDir(homeDir, sessionId);

Callers 2

Calls 3

rejectFunction · 0.85
onEventMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected