MCPcopy Index your code
hub / github.com/nodejs/node / writeBatchWithDrain

Function writeBatchWithDrain

lib/internal/quic/quic.js:1440–1459  ·  view source on GitHub ↗
(handle, stream, batch)

Source from the content-addressed store, hash-verified

1438// is larger -- the C++ side buffers the data and writeDesiredSize
1439// drops toward 0, letting the normal drain mechanism take over.
1440async 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
1461async function consumeAsyncSource(handle, stream, source) {
1462 handle.initStreamingSource();

Callers 2

consumeAsyncSourceFunction · 0.85
consumeSyncSourceFunction · 0.85

Calls 3

waitForDrainFunction · 0.70
writeMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected