Set minimum concurreny,

fix: call stop() if all tesks are processed
This commit is contained in:
2014-09-05 00:12:49 +05:30
parent ea2de93dbd
commit 63bbba174f
+10 -8
View File
@@ -40,15 +40,17 @@ JobManager.prototype.updateState = function(){
}; };
JobManager.prototype.setConcurrency = function( newVal ){ JobManager.prototype.setConcurrency = function( newVal ){
if( newVal > this.tmpPoolLen ){ if( newVal > 1){
var tmpPool = this.tmpPool; if( newVal > this.tmpPoolLen ){
var additionalPoolBlocks = Math.ceil( ( newVal - this.tmpPoolLen )/this.workers.length ), i; var tmpPool = this.tmpPool;
for( i=0; i < additionalPoolBlocks; i++){ var additionalPoolBlocks = Math.ceil( ( newVal - this.tmpPoolLen )/this.workers.length ), i;
tmpPool = tmpPool.concat( this.workers ); 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 self = this;
var task = self.tasks.splice(0, 1)[0]; var task = self.tasks.splice(0, 1)[0];
if( task == undefined ){ if( task == undefined ){
if( this.onStopped ){ this.onStopped(); } this.stop();
} }
var worker = self.getFromPool(); var worker = self.getFromPool();
this.work( task, worker, function(err){ this.work( task, worker, function(err){