From 63bbba174f3dc91fee5ddc76e5e43969f9a695db Mon Sep 17 00:00:00 2001 From: "Harish.K" Date: Fri, 5 Sep 2014 00:12:49 +0530 Subject: [PATCH] Set minimum concurreny, fix: call stop() if all tesks are processed --- src/JobManager.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/JobManager.js b/src/JobManager.js index da9a853..c592a0d 100644 --- a/src/JobManager.js +++ b/src/JobManager.js @@ -40,15 +40,17 @@ JobManager.prototype.updateState = function(){ }; JobManager.prototype.setConcurrency = function( newVal ){ - if( newVal > this.tmpPoolLen ){ - var tmpPool = this.tmpPool; - var additionalPoolBlocks = Math.ceil( ( newVal - this.tmpPoolLen )/this.workers.length ), i; - for( i=0; i < additionalPoolBlocks; i++){ - tmpPool = tmpPool.concat( this.workers ); + if( newVal > 1){ + if( newVal > this.tmpPoolLen ){ + var tmpPool = this.tmpPool; + var additionalPoolBlocks = Math.ceil( ( newVal - this.tmpPoolLen )/this.workers.length ), i; + for( i=0; i < additionalPoolBlocks; i++){ + tmpPool = tmpPool.concat( this.workers ); + } + this.tmpPoolLen += additionalPoolBlocks * this.workers.length ; } - this.tmpPoolLen += additionalPoolBlocks * this.workers.length ; + this.concurrency = newVal; } - this.concurrency = newVal; }; /* @@ -73,7 +75,7 @@ JobManager.prototype.$doWork_ = function( cb ){ var self = this; var task = self.tasks.splice(0, 1)[0]; if( task == undefined ){ - if( this.onStopped ){ this.onStopped(); } + this.stop(); } var worker = self.getFromPool(); this.work( task, worker, function(err){