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 2018-12-12 14:32:26 +01:00 committed by Rich Trott
parent ba4466e1b1
commit c9a7088bd8
2 changed files with 2 additions and 10 deletions

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;

View File

@ -375,7 +375,7 @@ function once(callback) {
return function(...args) {
if (called) return;
called = true;
callback(...args);
callback.apply(this, args);
};
}