Is there a tryWrite method like tryEnd or can there be?
difference with tryEnd being it won't require size argument when writing, but will give backpressure handling capability.
Example usage:
readStream.on('data', (buffer) => {
const chunk = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength),
lastOffset = res.getWriteOffset();
// First try
const ok = res.tryWrite(chunk);
if (!ok) {
// pause because backpressure
readStream.pause();
// Save unsent chunk for later
res.ab = chunk;
res.abOffset = lastOffset;
// Register async handlers for drainage
res.onWritable((offset) => {
const ok = res.tryWrite(res.ab.slice(offset - res.abOffset));
if (ok) {
readStream.resume();
}
return ok;
});
}
});
readStream.on('end', () => res.end());
or are there are alternatives?
Is there a
tryWritemethod liketryEndor can there be?difference with
tryEndbeing it won't require size argument when writing, but will give backpressure handling capability.Example usage:
or are there are alternatives?