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:
parent
ba4466e1b1
commit
c9a7088bd8
@ -7,20 +7,12 @@ const {
|
|||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
ERR_STREAM_PREMATURE_CLOSE
|
ERR_STREAM_PREMATURE_CLOSE
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
|
const { once } = require('internal/util');
|
||||||
|
|
||||||
function isRequest(stream) {
|
function isRequest(stream) {
|
||||||
return stream.setHeader && typeof stream.abort === 'function';
|
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) {
|
function eos(stream, opts, callback) {
|
||||||
if (arguments.length === 2) {
|
if (arguments.length === 2) {
|
||||||
callback = opts;
|
callback = opts;
|
||||||
|
@ -375,7 +375,7 @@ function once(callback) {
|
|||||||
return function(...args) {
|
return function(...args) {
|
||||||
if (called) return;
|
if (called) return;
|
||||||
called = true;
|
called = true;
|
||||||
callback(...args);
|
callback.apply(this, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user