stream: re-use existing once() implementation

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Anna Henningsen authored and Beth Griggs committed 2018-12-17 23:59:39 +00:00
1 parent e04e85460f
commit d449c36500
2 files changed
+2 -10

No files matched your search

+1 -9
View File
@@ -7,20 +7,12 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PREMATURE_CLOSE
} = require('internal/errors').codes;
const { once } = require('internal/util');
function isRequest(stream) {
return stream.setHeader && typeof stream.abort === 'function';
}
function once(callback) {
let called = false;
return function(err) {
if (called) return;
called = true;
callback.call(this, err);
};
}
function eos(stream, opts, callback) {
if (arguments.length === 2) {
callback = opts;
+1 -1
View File
@@ -375,7 +375,7 @@ function once(callback) {
return function(...args) {
if (called) return;
called = true;
callback(...args);
callback.apply(this, args);
};
}