@ -22,6 +22,8 @@ function JobManager(opts){
this . isLoadingTakingPlace = false ;
this . isLoadingTakingPlace = false ;
this . endReached = false ;
this . endReached = false ;
this . runningTasks = 0 ;
this . runningTasks = 0 ;
this . tmpPoolLen = 0 ;
this . tmpPool = [ ] ;
}
}
/ *
/ *
* JobManager . prototype . __ defineSetter__ ( 'workers' , function ( workers ) {
* JobManager . prototype . __ defineSetter__ ( 'workers' , function ( workers ) {
@ -31,18 +33,10 @@ function JobManager(opts){
* /
* /
JobManager . prototype . updateState = function ( ) {
JobManager . prototype . updateState = function ( ) {
var workers = this . workers ;
var tmpPoolBlock = workers . length && Math . ceil ( this . concurrency / workers . length ) , i ;
var tmpPool = [ ] ;
for ( i = 0 ; i < tmpPoolBlock ; i ++ ) {
tmpPool = tmpPool . concat ( this . workers ) ;
}
this . tmpPool = tmpPool ;
this . tmpPoolLen = tmpPoolBlock * this . workers . length ;
this . updateTmpPool ( this . concurrency ) ;
} ;
} ;
JobManager . prototype . setConcurrency = function ( newVal ) {
if ( newVal > this . minConcurrency ) {
JobManager . prototype . updateTmpPool = function ( newVal ) {
if ( newVal > this . tmpPoolLen ) {
if ( newVal > this . tmpPoolLen ) {
var tmpPool = this . tmpPool ;
var tmpPool = this . tmpPool ;
var additionalPoolBlocks = Math . ceil ( ( newVal - this . tmpPoolLen ) / this . workers . length ) , i ;
var additionalPoolBlocks = Math . ceil ( ( newVal - this . tmpPoolLen ) / this . workers . length ) , i ;
@ -50,7 +44,13 @@ JobManager.prototype.setConcurrency = function( newVal ){
tmpPool = tmpPool . concat ( this . workers ) ;
tmpPool = tmpPool . concat ( this . workers ) ;
}
}
this . tmpPoolLen += additionalPoolBlocks * this . workers . length ;
this . tmpPoolLen += additionalPoolBlocks * this . workers . length ;
this . tmpPool = tmpPool ;
}
}
} ;
JobManager . prototype . setConcurrency = function ( newVal ) {
if ( newVal > this . minConcurrency ) {
this . updateTmpPool ( newVal ) ;
this . concurrency = newVal ;
this . concurrency = newVal ;
}
}
} ;
} ;
@ -90,11 +90,11 @@ JobManager.prototype.$doWork_ = function( cb ){
self . $onLoadMore ( ) ;
self . $onLoadMore ( ) ;
}
}
}
}
cb ( ) ;
if ( self . state == STATE . NOT_RUNNING ) {
if ( self . state == STATE . NOT_RUNNING ) {
if ( ( self . runningTasks == 1 ) && self . onStopped ) { self . onStopped ( ) ; }
if ( ( self . runningTasks == 1 ) && self . onStopped ) { self . onStopped ( ) ; }
}
}
self . returnToPool ( worker ) ;
self . returnToPool ( worker ) ;
cb ( ) ;
} ) ;
} ) ;
} ;
} ;