Skip to content

Commit

Permalink
[api minor] Concurrency limit can now also be set via options.limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
AvianFlu committed Nov 18, 2011
1 parent ca642cc commit 4dbff81
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/ncp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ ncp.ncp = function (source, dest, options, callback) {
errs = null,
started = 0,
finished = 0,
running = 0;
running = 0,
limit = options.limit || ncp.limit || 16;

ncp.limit = (ncp.limit < 1) ? 1 : (ncp.limit > 512) ? 512 : ncp.limit;
limit = (limit < 1) ? 1 : (limit > 512) ? 512 : limit;

startCopy(currentPath);

Expand All @@ -42,7 +43,7 @@ ncp.ncp = function (source, dest, options, callback) {
}

function getStats(item) {
if (running >= ncp.limit) {
if (running >= limit) {
return process.nextTick(function () {
getStats(item);
});
Expand Down Expand Up @@ -80,9 +81,7 @@ ncp.ncp = function (source, dest, options, callback) {
var readStream = fs.createReadStream(file),
writeStream = fs.createWriteStream(target);
readStream.pipe(writeStream);
readStream.once('end', function () {
return cb();
});
readStream.once('end', cb);
}

function rmFile(file, done) {
Expand Down Expand Up @@ -118,7 +117,7 @@ ncp.ncp = function (source, dest, options, callback) {
if (err) {
return onError(err);
}
items.forEach( function (item) {
items.forEach(function (item) {
startCopy(dir + '/' + item);
});
return cb();
Expand Down Expand Up @@ -193,6 +192,5 @@ ncp.ncp = function (source, dest, options, callback) {
}
}

ncp.limit = 16;


0 comments on commit 4dbff81

Please sign in to comment.