diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index 4ad7b93337f633..1753996a4f85de 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -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; diff --git a/lib/internal/util.js b/lib/internal/util.js index 23c201da371099..3aa00fed35957f 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -375,7 +375,7 @@ function once(callback) { return function(...args) { if (called) return; called = true; - callback(...args); + callback.apply(this, args); }; }