Skip to content

Commit d449c36

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 e04e854 commit d449c36

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
@@ -7,20 +7,12 @@ const {
77
ERR_INVALID_ARG_TYPE,
88
ERR_STREAM_PREMATURE_CLOSE
99
} = require('internal/errors').codes;
10+
const { once } = require('internal/util');
1011

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

15-
function once(callback) {
16-
let called = false;
17-
return function(err) {
18-
if (called) return;
19-
called = true;
20-
callback.call(this, err);
21-
};
22-
}
23-
2416
function eos(stream, opts, callback) {
2517
if (arguments.length === 2) {
2618
callback = opts;

lib/internal/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function once(callback) {
375375
return function(...args) {
376376
if (called) return;
377377
called = true;
378-
callback(...args);
378+
callback.apply(this, args);
379379
};
380380
}
381381

0 commit comments

Comments
 (0)