(
streamId: number,
stream: ReadableStream<Uint8Array>,
)
| 167 | |
| 168 | // Pump a single raw stream with its streamId |
| 169 | const pumpRawStream = async ( |
| 170 | streamId: number, |
| 171 | stream: ReadableStream<Uint8Array>, |
| 172 | ) => { |
| 173 | const reader = stream.getReader() |
| 174 | cancelReaders.push(() => { |
| 175 | // Catch async rejection - reader may already be released |
| 176 | reader.cancel().catch(() => {}) |
| 177 | }) |
| 178 | try { |
| 179 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 180 | while (true) { |
| 181 | const { done, value } = await reader.read() |
| 182 | // Check cancelled after await - flag may have changed while waiting |
| 183 | if (cancelled) break |
| 184 | if (done) { |
| 185 | safeEnqueue(encodeEndFrame(streamId)) |
| 186 | break |
| 187 | } |
| 188 | safeEnqueue(encodeChunkFrame(streamId, value)) |
| 189 | } |
| 190 | } catch (error) { |
| 191 | // Stream error - send ERROR frame (non-fatal, other streams continue) |
| 192 | safeEnqueue(encodeErrorFrame(streamId, error)) |
| 193 | } finally { |
| 194 | reader.releaseLock() |
| 195 | checkComplete() |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // Start all pumps concurrently |
| 200 | pumpJSON() |
no test coverage detected