(
session: {
onEvent(listener: (event: Event) => void): () => void;
},
predicate: (event: Event) => boolean,
timeoutMs = 1_000,
)
| 52 | } |
| 53 | |
| 54 | export 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 | |
| 75 | async function readWireEvents(homeDir: string, sessionId: string): Promise<readonly unknown[]> { |
| 76 | const sessionDir = await readIndexedSessionDir(homeDir, sessionId); |
no test coverage detected