Skip to content

Commit

Permalink
fixup: always register eos
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 29, 2020
1 parent b40a103 commit 81de706
Showing 1 changed file with 11 additions and 6 deletions.
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

0 comments on commit 81de706

Please sign in to comment.