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

Function waitForEvent

nodejs/test/e2e/rpc_session_state.e2e.test.ts:797–822  ·  view source on GitHub ↗
(
    session: CopilotSession,
    predicate: (event: SessionEvent) => event is T,
    description: string,
    timeoutMs = 15_000
)

Source from the content-addressed store, hash-verified

795}
796
797function waitForEvent<T extends SessionEvent>(
798 session: CopilotSession,
799 predicate: (event: SessionEvent) => event is T,
800 description: string,
801 timeoutMs = 15_000
802): Promise<T> {
803 return new Promise<T>((resolve, reject) => {
804 let unsubscribe: () => void = () => {};
805 const timeout = setTimeout(() => {
806 unsubscribe();
807 reject(new Error(`Timed out waiting for ${description}`));
808 }, timeoutMs);
809
810 unsubscribe = session.on((event) => {
811 if (predicate(event)) {
812 clearTimeout(timeout);
813 unsubscribe();
814 resolve(event);
815 } else if (event.type === "session.error") {
816 clearTimeout(timeout);
817 unsubscribe();
818 reject(new Error(`${event.data.message}\n${event.data.stack ?? ""}`));
819 }
820 });
821 });
822}

Callers 1

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…