Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup: always register eos
  • Loading branch information
ronag committed Feb 29, 2020
commit 81de706be6d4a9c0aa1d8804668e4107417b0aee
17 changes: 11 additions & 6 deletions lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { once } = require('internal/util');
let eos;

function destroy(err, cb) {
Expand All @@ -11,13 +12,17 @@ function destroy(err, cb) {
err = null;
}

if (typeof cb === 'function') {
// TODO(ronag): Remove once cb is invoked only through eos.
cb = once(cb);

if (!eos) eos = require('internal/streams/end-of-stream');
eos(this, (err) => {
cb(err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE' ? err : undefined);
});
}

if ((w && w.destroyed) || (r && r.destroyed)) {
if (typeof cb === 'function') {
if (!eos) eos = require('internal/streams/end-of-stream');
eos(this, (err) => {
cb(err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE' ? err : undefined);
});
}
return this;
}

Expand Down