@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
25 lines (24 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pipelineClose = void 0;
function pipelineClose(name, readableDownstream, sourceReadable, streamDone, logger) {
readableDownstream.push(null); // this closes the stream, so downstream Readable will receive `end` and won't write anything
if (!sourceReadable) {
logger.warn(`${name} sourceReadable is not provided, readable stream will not be stopped`);
}
else {
logger.log(`${name} is calling readable.unpipe() to pause the stream`);
sourceReadable.unpipe(); // it is expected to pause the stream
if (!streamDone) {
logger.log(`${name} streamDone is not provided, will do readable.destroy right away`);
sourceReadable.destroy();
}
else {
void streamDone.then(() => {
logger.log(`${name} streamDone, calling readable.destroy()`);
sourceReadable.destroy(); // this throws ERR_STREAM_PREMATURE_CLOSE
});
}
}
}
exports.pipelineClose = pipelineClose;