MCPcopy Create free account
hub / github.com/github/copilot-sdk / waitForEvent

Function waitForEvent

nodejs/test/e2e/rpc_event_side_effects.e2e.test.ts:13–38  ·  view source on GitHub ↗
(
    session: CopilotSession,
    predicate: (event: SessionEvent) => event is T,
    description: string,
    timeoutMs = EVENT_TIMEOUT_MS
)

Source from the content-addressed store, hash-verified

11const EVENT_TIMEOUT_MS = 30_000;
12
13function waitForEvent<T extends SessionEvent>(
14 session: CopilotSession,
15 predicate: (event: SessionEvent) => event is T,
16 description: string,
17 timeoutMs = EVENT_TIMEOUT_MS
18): Promise<T> {
19 return new Promise<T>((resolve, reject) => {
20 let unsubscribe: () => void = () => {};
21 const timer = setTimeout(() => {
22 unsubscribe();
23 reject(new Error(`Timed out waiting for ${description}`));
24 }, timeoutMs);
25
26 unsubscribe = session.on((event) => {
27 if (predicate(event)) {
28 clearTimeout(timer);
29 unsubscribe();
30 resolve(event);
31 } else if (event.type === "session.error") {
32 clearTimeout(timer);
33 unsubscribe();
34 reject(new Error(`${event.data.message}\n${event.data.stack ?? ""}`));
35 }
36 });
37 });
38}
39
40describe("Session RPC event side effects", async () => {
41 const { copilotClient: client } = await createSdkTestContext();

Calls 3

predicateFunction · 0.85
unsubscribeFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…