Comparing version 0.1.13 to 0.2.0
@@ -9,6 +9,8 @@ /** | ||
* | ||
* @version 0.1.13 | ||
* @version 0.2.0 | ||
*/ | ||
var Vow = require('vow'), | ||
Queue = require('./queue'), | ||
openFilesQueue = new Queue(), | ||
fs = require('fs'), | ||
@@ -35,23 +37,25 @@ path = require('path'), | ||
emfileTimeout = 1, | ||
emfileFixWrapper = function(method) { | ||
var wrapper = function() { | ||
var callArgs = arguments; | ||
return method.apply(vfs, callArgs).then( | ||
function(res) { | ||
emfileTimeout = Math.max(1, emfileTimeout / 2); | ||
return res; | ||
}, | ||
function(err) { | ||
if(err.code === 'EMFILE') { | ||
emfileTimeout++; | ||
return Vow.delay(null, emfileTimeout).then(function() { | ||
return wrapper.apply(vfs, callArgs); | ||
emfileFixWrapper = function(method, weight) { | ||
var wrapper = function() { | ||
var callArgs = arguments; | ||
return openFilesQueue.enqueue(function() { | ||
return method.apply(vfs, callArgs).then( | ||
function(res) { | ||
emfileTimeout = Math.max(1, emfileTimeout / 2); | ||
return res; | ||
}, | ||
function(err) { | ||
if(err.code === 'EMFILE') { | ||
emfileTimeout++; | ||
return Vow.delay(null, emfileTimeout).then(function() { | ||
return wrapper.apply(vfs, callArgs); | ||
}); | ||
} | ||
else { | ||
throw err; | ||
} | ||
}); | ||
} | ||
else { | ||
throw err; | ||
} | ||
}); | ||
}; | ||
return wrapper; | ||
}, weight); | ||
}; | ||
return wrapper; | ||
}, | ||
@@ -130,3 +134,3 @@ undef; | ||
}); | ||
}), | ||
}, 2), | ||
@@ -341,3 +345,9 @@ /** | ||
}); | ||
}, | ||
options : function(opts) { | ||
if(typeof opts.openFileLimit !== 'undefined') { | ||
openFilesQueue.setMaxWeight(opts.openFileLimit); | ||
} | ||
} | ||
}; |
{ | ||
"name" : "vow-fs", | ||
"version" : "0.1.13", | ||
"version" : "0.2.0", | ||
"description" : "File I/O by Vow", | ||
@@ -20,6 +20,6 @@ "homepage" : "https://github.com/dfilatov/vow-fs", | ||
"peerDependencies": { | ||
"vow" : ">= 0.1.x" | ||
"vow" : ">= 0.3.9" | ||
}, | ||
"devDependencies": { | ||
"vow" : ">= 0.1.x", | ||
"vow" : ">= 0.3.9", | ||
"nodeunit" : "", | ||
@@ -26,0 +26,0 @@ "istanbul" : "" |
33697
14
931