Comparing version 0.3.13 to 0.3.14
@@ -63,3 +63,3 @@ /* eslint max-lines: off */ | ||
if (err && (err.code === "EMFILE" || err.code === "ENFILE")) { | ||
if (limit > openCount) limit = openCount; | ||
if (limit > openCount) limit = openCount - 1; | ||
queue.push({ fn: self, context, args }); | ||
@@ -77,3 +77,71 @@ release(); | ||
const wrapPromised = function () { | ||
const handlePromised = function () { | ||
const { open } = fs.promises; | ||
fs.promises.open = defineLength(function (...args) { | ||
if (count >= limit) { | ||
const deferred = getDeferred(); | ||
queue.push({ fn: fs.promises.open, context: this, args, deferred }); | ||
return deferred.promise; | ||
} | ||
const openCount = count++; | ||
++debugStats.promisesFd; | ||
return open(...args).then( | ||
handle => { | ||
const { close } = handle; | ||
handle.close = function () { | ||
return close.call(this).then(() => { | ||
--debugStats.promisesFd; | ||
--count; | ||
release(); | ||
}); | ||
return callback ? undefined : promise; | ||
}; | ||
return handle; | ||
}, | ||
function (error) { | ||
--debugStats.promisesFd; | ||
--count; | ||
if (err.code === "EMFILE" || err.code === "ENFILE") { | ||
if (limit > openCount) limit = openCount - 1; | ||
const deferred = getDeferred(); | ||
queue.push({ fn: fs.open, context: this, args, deferred }); | ||
release(); | ||
return deferred.promise; | ||
} | ||
release(); | ||
throw error; | ||
} | ||
); | ||
}, fs.promises.open.length); | ||
const wrapPromised = function (asyncFn, type) { | ||
let self; | ||
debugStats[type] = 0; | ||
return (self = defineLength(function (...args) { | ||
if (count >= limit) { | ||
const deferred = getDeferred(); | ||
queue.push({ fn: self, context: this, args, deferred }); | ||
return deferred.promise; | ||
} | ||
const openCount = count++; | ||
++debugStats[type]; | ||
return asyncFn(...args).catch(error => { | ||
--debugStats[type]; | ||
--count; | ||
if (error.code === "EMFILE" || error.code === "ENFILE") { | ||
if (limit > openCount) limit = openCount - 1; | ||
const deferred = getDeferred(); | ||
queue.push({ fn: fs.promises.opendir, context: this, args, deferred }); | ||
release(); | ||
return deferred.promise; | ||
} | ||
release(); | ||
throw error; | ||
}); | ||
}, asyncFn.length)); | ||
}; | ||
fs.promises.writeFile = wrapPromised(fs.promises.writeFile, "promisesWriteFile"); | ||
if (fs.opendirSync) { | ||
@@ -137,3 +205,3 @@ const wrapDirEntries = require("./lib/wrap-dir-entries"); | ||
if (error.code === "EMFILE" || error.code === "ENFILE") { | ||
if (limit > openCount) limit = openCount; | ||
if (limit > openCount) limit = openCount - 1; | ||
const deferred = getDeferred(); | ||
@@ -182,3 +250,3 @@ queue.push({ fn: fs.promises.opendir, context: this, args, deferred }); | ||
if (err.code === "EMFILE" || err.code === "ENFILE") { | ||
if (limit > openCount) limit = openCount; | ||
if (limit > openCount) limit = openCount - 1; | ||
queue.push({ fn: fs.open, context: this, args }); | ||
@@ -224,3 +292,3 @@ release(); | ||
if (fs.promises) wrapPromised(); | ||
if (fs.promises) handlePromised(); | ||
@@ -227,0 +295,0 @@ Object.defineProperty(exports, "initialized", d("e", true)); |
{ | ||
"name": "fs2", | ||
"version": "0.3.13", | ||
"version": "0.3.14", | ||
"description": "fs (file system package) extensions", | ||
@@ -5,0 +5,0 @@ "author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108213
3242