Skip to content

Commit 3f969d6

Browse files
addaleaxBethGriggs
authored andcommitted
stream: re-use existing once() implementation
PR-URL: #24991 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 48c5413 commit 3f969d6

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

lib/internal/streams/end-of-stream.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,14 @@
66
const {
77
ERR_STREAM_PREMATURE_CLOSE
88
} = require('internal/errors').codes;
9+
const { once } = require('internal/util');
910

1011
function noop() {}
1112

1213
function isRequest(stream) {
1314
return stream.setHeader && typeof stream.abort === 'function';
1415
}
1516

16-
function once(callback) {
17-
let called = false;
18-
return function(err) {
19-
if (called) return;
20-
called = true;
21-
callback.call(this, err);
22-
};
23-
}
24-
2517
function eos(stream, opts, callback) {
2618
if (typeof opts === 'function') return eos(stream, null, opts);
2719
if (!opts) opts = {};

lib/internal/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function once(callback) {
368368
return function(...args) {
369369
if (called) return;
370370
called = true;
371-
callback(...args);
371+
callback.apply(this, args);
372372
};
373373
}
374374

0 commit comments

Comments
 (0)