We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b40a103 commit 81de706Copy full SHA for 81de706
1 file changed
lib/internal/streams/destroy.js
@@ -1,5 +1,6 @@
1
'use strict';
2
3
+const { once } = require('internal/util');
4
let eos;
5
6
function destroy(err, cb) {
@@ -11,13 +12,17 @@ function destroy(err, cb) {
11
12
err = null;
13
}
14
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
25
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);
- });
- }
26
return this;
27
28
0 commit comments