()
| 142 | |
| 143 | // Pump JSON stream (streamId 0) |
| 144 | const pumpJSON = async () => { |
| 145 | const reader = jsonStream.getReader() |
| 146 | cancelReaders.push(() => { |
| 147 | // Catch async rejection - reader may already be released |
| 148 | reader.cancel().catch(() => {}) |
| 149 | }) |
| 150 | try { |
| 151 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 152 | while (true) { |
| 153 | const { done, value } = await reader.read() |
| 154 | // Check cancelled after await - flag may have changed while waiting |
| 155 | if (cancelled) break |
| 156 | if (done) break |
| 157 | safeEnqueue(encodeJSONFrame(value)) |
| 158 | } |
| 159 | } catch (error) { |
| 160 | // JSON stream error - fatal, error the whole response |
| 161 | safeError(error) |
| 162 | } finally { |
| 163 | reader.releaseLock() |
| 164 | checkComplete() |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | // Pump a single raw stream with its streamId |
| 169 | const pumpRawStream = async ( |
no test coverage detected