Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d449c36

Browse filesBrowse files
addaleaxBethGriggs
authored andcommitted
stream: re-use existing once() implementation
PR-URL: #24991 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent e04e854 commit d449c36
Copy full SHA for d449c36

File tree

Expand file treeCollapse file tree

2 files changed

+2
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+2
-10
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/streams/end-of-stream.js
+1-9Lines changed: 1 addition & 9 deletions
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;
Collapse file

‎lib/internal/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/util.js
+1-1Lines changed: 1 addition & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.