File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -103,13 +103,20 @@ class Master {
103103 this . peer . register ( 'requestWork' , ( pk , args , cb ) => {
104104 switch ( true ) {
105105 case this . jobs . length > 1 : {
106+ if ( args . getBatch && this . jobs . length > args . batchSize ) {
107+ args . batchTasks = this . jobs . splice ( 0 , args . batchSize ) ; // splice mutates original array which slices it
108+ this . log . debug (
109+ `task queue reduced:${ this . jobs . length } - ${ args . batchSize } `
110+ ) ;
111+ break ;
112+ }
106113 args . task = this . jobs . shift ( ) ;
107114 this . log . debug ( `task queue reduced:${ this . jobs . length } ` ) ;
108115 break ;
109116 }
110117 case this . jobs . length === 1 : {
111- // shift make array undefined on last element
112- [ args . task ] = this . jobs ; // , correct this with this check
118+ // shift leaves array undefined on last element
119+ [ args . task ] = this . jobs ; // this case is to avoid that
113120 this . jobs = [ ] ;
114121 this . log . debug ( `task queue finished:${ this . jobs . length } ` ) ;
115122 break ;
You can’t perform that action at this time.
0 commit comments