From ea2de93dbda73b853db01785cd82b373363f733d Mon Sep 17 00:00:00 2001 From: "Harish.K" Date: Mon, 1 Sep 2014 15:28:15 +0530 Subject: [PATCH] Fix: setConcurrency --- src/JobManager.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/JobManager.js b/src/JobManager.js index 04f3e43..da9a853 100644 --- a/src/JobManager.js +++ b/src/JobManager.js @@ -48,6 +48,7 @@ JobManager.prototype.setConcurrency = function( newVal ){ } this.tmpPoolLen += additionalPoolBlocks * this.workers.length ; } + this.concurrency = newVal; }; /* @@ -70,8 +71,11 @@ JobManager.prototype.getFromPool = function(){ JobManager.prototype.$doWork_ = function( cb ){ var self = this; - var worker = self.getFromPool(); var task = self.tasks.splice(0, 1)[0]; + if( task == undefined ){ + if( this.onStopped ){ this.onStopped(); } + } + var worker = self.getFromPool(); this.work( task, worker, function(err){ if(err){ self.onError(err, task, worker ); @@ -114,6 +118,12 @@ JobManager.prototype.pause = function(){ this.state = STATE.NOT_RUNNING; }; +JobManager.prototype.stop = function(){ + this.state = STATE.NOT_RUNNING; + if( this.onStopped ){ this.onStopped(); } +}; + + JobManager.prototype.resume = function(){ this.start(); };