Skip to content

Commit 81de706

Browse files
committed
fixup: always register eos
1 parent b40a103 commit 81de706

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/internal/streams/destroy.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const { once } = require('internal/util');
34
let eos;
45

56
function destroy(err, cb) {
@@ -11,13 +12,17 @@ function destroy(err, cb) {
1112
err = null;
1213
}
1314

15+
if (typeof cb === 'function') {
16+
// TODO(ronag): Remove once cb is invoked only through eos.
17+
cb = once(cb);
18+
19+
if (!eos) eos = require('internal/streams/end-of-stream');
20+
eos(this, (err) => {
21+
cb(err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE' ? err : undefined);
22+
});
23+
}
24+
1425
if ((w && w.destroyed) || (r && r.destroyed)) {
15-
if (typeof cb === 'function') {
16-
if (!eos) eos = require('internal/streams/end-of-stream');
17-
eos(this, (err) => {
18-
cb(err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE' ? err : undefined);
19-
});
20-
}
2126
return this;
2227
}
2328

0 commit comments

Comments
 (0)