Wait for an event of `type`, or give up. Never polls the server.
(type: string, timeoutMs = 12_000)
| 147 | |
| 148 | /** Wait for an event of `type`, or give up. Never polls the server. */ |
| 149 | async waitFor(type: string, timeoutMs = 12_000): Promise<SseEvent> { |
| 150 | const deadline = Date.now() + timeoutMs; |
| 151 | for (;;) { |
| 152 | const hit = this.events.find((e) => e.event === type); |
| 153 | if (hit) return hit; |
| 154 | if (Date.now() > deadline) { |
| 155 | throw new Error( |
| 156 | `No "${type}" event within ${timeoutMs}ms. Saw: ${this.events.map((e) => e.event).join(', ') || '(nothing)'}` |
| 157 | ); |
| 158 | } |
| 159 | await new Promise((r) => setTimeout(r, 25)); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | close(): void { |
| 164 | this.res?.destroy(); |
no test coverage detected