(handle, stream, batch)
| 1438 | // is larger -- the C++ side buffers the data and writeDesiredSize |
| 1439 | // drops toward 0, letting the normal drain mechanism take over. |
| 1440 | async function writeBatchWithDrain(handle, stream, batch) { |
| 1441 | const state = getQuicStreamState(stream); |
| 1442 | |
| 1443 | if (state.writeDesiredSize === 0) { |
| 1444 | await waitForDrain(stream); |
| 1445 | if (stream.destroyed) return true; |
| 1446 | } |
| 1447 | |
| 1448 | // Write the batch. The return value is the total queued byte count |
| 1449 | // on success, or undefined on failure (e.g., DataQueue append |
| 1450 | // rejected). Guard against silent data loss. |
| 1451 | const result = handle.write(batch); |
| 1452 | if (result === undefined) { |
| 1453 | if (!stream.destroyed) { |
| 1454 | stream.destroy(new ERR_INVALID_STATE('Stream write failed')); |
| 1455 | } |
| 1456 | return true; |
| 1457 | } |
| 1458 | return false; |
| 1459 | } |
| 1460 | |
| 1461 | async function consumeAsyncSource(handle, stream, source) { |
| 1462 | handle.initStreamingSource(); |
no test coverage detected