Skip to content

Commit 3f969d6

Browse 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 48c5413 commit 3f969d6

2 files changed

Lines changed: 2 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 9 deletions
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
functionnoop(){}
1112

1213
functionisRequest(stream){
1314
returnstream.setHeader&&typeofstream.abort==='function';
1415
}
1516

16-
functiononce(callback){
17-
letcalled=false;
18-
returnfunction(err){
19-
if(called)return;
20-
called=true;
21-
callback.call(this,err);
22-
};
23-
}
24-
2517
functioneos(stream,opts,callback){
2618
if(typeofopts==='function')returneos(stream,null,opts);
2719
if(!opts)opts={};

‎lib/internal/util.js‎

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

0 commit comments

Comments
 (0)