aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/internal/fs/utils.js2
-rw-r--r--lib/internal/streams/pipeline.js10
-rw-r--r--lib/internal/util.js10
3 files changed, 13 insertions, 9 deletions
diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js
index acc566e37b..362383be48 100644
--- a/lib/internal/fs/utils.js
+++ b/lib/internal/fs/utils.js
@@ -10,6 +10,7 @@ const {
ERR_OUT_OF_RANGE
} = require('internal/errors').codes;
const { isUint8Array, isArrayBufferView } = require('internal/util/types');
+const { once } = require('internal/util');
const pathModule = require('path');
const util = require('util');
const kType = Symbol('type');
@@ -123,6 +124,7 @@ function getDirents(path, [names, types], callback) {
if (typeof callback == 'function') {
const len = names.length;
let toFinish = 0;
+ callback = once(callback);
for (i = 0; i < len; i++) {
const type = types[i];
if (type === UV_DIRENT_UNKNOWN) {
diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js
index caa4042339..bce466db74 100644
--- a/lib/internal/streams/pipeline.js
+++ b/lib/internal/streams/pipeline.js
@@ -5,21 +5,13 @@
let eos;
+const { once } = require('internal/util');
const {
ERR_INVALID_CALLBACK,
ERR_MISSING_ARGS,
ERR_STREAM_DESTROYED
} = require('internal/errors').codes;
-function once(callback) {
- let called = false;
- return function(err) {
- if (called) return;
- called = true;
- callback(err);
- };
-}
-
function isRequest(stream) {
return stream.setHeader && typeof stream.abort === 'function';
}
diff --git a/lib/internal/util.js b/lib/internal/util.js
index 43b9974068..5cb1b281ba 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -365,6 +365,15 @@ function isInsideNodeModules() {
return false;
}
+function once(callback) {
+ let called = false;
+ return function(...args) {
+ if (called) return;
+ called = true;
+ callback(...args);
+ };
+}
+
module.exports = {
assertCrypto,
cachedResult,
@@ -381,6 +390,7 @@ module.exports = {
join,
normalizeEncoding,
objectToString,
+ once,
promisify,
spliceOne,
removeColors,