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

Function waitForSDKEvent

packages/node-sdk/examples/runtime-smoke-helpers.ts:64–88  ·  view source on GitHub ↗
(
  session: Session,
  predicate: (event: Event) => boolean,
  timeoutMs = 30_000,
)

Source from the content-addressed store, hash-verified

62}
63
64export function waitForSDKEvent(
65 session: Session,
66 predicate: (event: Event) => boolean,
67 timeoutMs = 30_000,
68): Promise<Event> {
69 return new Promise((resolve, reject) => {
70 const timeout = setTimeout(() => {
71 unsubscribe();
72 reject(new Error('Timed out waiting for session event'));
73 }, timeoutMs);
74 const unsubscribe = session.onEvent((event) => {
75 logEvent(event);
76 if (event.type === 'error') {
77 clearTimeout(timeout);
78 unsubscribe();
79 reject(new Error(`${event.code}: ${event.message}`));
80 return;
81 }
82 if (!predicate(event)) return;
83 clearTimeout(timeout);
84 unsubscribe();
85 resolve(event);
86 });
87 });
88}
89
90interface PromptStreamWatcher {
91 readonly started: Promise<number>;

Callers

nothing calls this directly

Calls 4

rejectFunction · 0.85
logEventFunction · 0.85
resolveFunction · 0.70
onEventMethod · 0.65

Tested by

no test coverage detected