| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aa05c8b commit f0a4017
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ const { | |||
| 10 | 10 | ERR_OUT_OF_RANGE | |
| 11 | 11 | } = require('internal/errors').codes; | |
| 12 | 12 | const { isUint8Array, isArrayBufferView } = require('internal/util/types'); | |
| 13 | + const { once } = require('internal/util'); | ||
| 13 | 14 | const pathModule = require('path'); | |
| 14 | 15 | const util = require('util'); | |
| 15 | 16 | const kType = Symbol('type'); | |
@@ -123,6 +124,7 @@ function getDirents(path, [names, types], callback) { | |||
| 123 | 124 | if (typeof callback == 'function') { | |
| 124 | 125 | const len = names.length; | |
| 125 | 126 | let toFinish = 0; | |
| 127 | + callback = once(callback); | ||
| 126 | 128 | for (i = 0; i < len; i++) { | |
| 127 | 129 | const type = types[i]; | |
| 128 | 130 | if (type === UV_DIRENT_UNKNOWN) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,20 +5,12 @@ | |||
| 5 | 5 | ||
| 6 | 6 | let eos; | |
| 7 | 7 | ||
| 8 | + const { once } = require('internal/util'); | ||
| 8 | 9 | const { | |
| 9 | 10 | ERR_MISSING_ARGS, | |
| 10 | 11 | ERR_STREAM_DESTROYED | |
| 11 | 12 | } = require('internal/errors').codes; | |
| 12 | 13 | ||
| 13 | - function once(callback) { | ||
| 14 | - let called = false; | ||
| 15 | - return function(err) { | ||
| 16 | - if (called) return; | ||
| 17 | - called = true; | ||
| 18 | - callback(err); | ||
| 19 | - }; | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | 14 | function noop(err) { | |
| 23 | 15 | // Rethrow the error if it exists to avoid swallowing it | |
| 24 | 16 | if (err) throw err; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -364,6 +364,15 @@ function isInsideNodeModules() { | |||
| 364 | 364 | return false; | |
| 365 | 365 | } | |
| 366 | 366 | ||
| 367 | + function once(callback) { | ||
| 368 | + let called = false; | ||
| 369 | + return function(...args) { | ||
| 370 | + if (called) return; | ||
| 371 | + called = true; | ||
| 372 | + callback(...args); | ||
| 373 | + }; | ||
| 374 | + } | ||
| 375 | + | ||
| 367 | 376 | module.exports = { | |
| 368 | 377 | assertCrypto, | |
| 369 | 378 | cachedResult, | |
@@ -380,6 +389,7 @@ module.exports = { | |||
| 380 | 389 | join, | |
| 381 | 390 | normalizeEncoding, | |
| 382 | 391 | objectToString, | |
| 392 | + once, | ||
| 383 | 393 | promisify, | |
| 384 | 394 | spliceOne, | |
| 385 | 395 | removeColors, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments