@@ -358,18 +358,8 @@ export abstract class AbstractPool<
358358 : accumulator ,
359359 0 ,
360360 ) ,
361- stealingWorkerNodes : this . workerNodes . reduce (
362- ( accumulator , _ , workerNodeKey ) =>
363- this . isWorkerNodeStealing ( workerNodeKey )
364- ? accumulator + 1
365- : accumulator ,
366- 0 ,
367- ) ,
368- queuedTasks : this . workerNodes . reduce (
369- ( accumulator , workerNode ) =>
370- accumulator + workerNode . usage . tasks . queued ,
371- 0 ,
372- ) ,
361+ stealingWorkerNodes : this . getStealingWorkerNodes ( ) ,
362+ queuedTasks : this . getQueuedTasks ( ) ,
373363 maxQueuedTasks : this . workerNodes . reduce (
374364 ( accumulator , workerNode ) =>
375365 accumulator + ( workerNode . usage . tasks . maxQueued ?? 0 ) ,
@@ -852,6 +842,9 @@ export abstract class AbstractPool<
852842 message : MessageValue < Data > ,
853843 ) : Promise < boolean > {
854844 const targetWorkerNodeKeys = [ ...this . workerNodes . keys ( ) ]
845+ if ( targetWorkerNodeKeys . length === 0 ) {
846+ return true
847+ }
855848 const responsesReceived : MessageValue < Response > [ ] = [ ]
856849 const taskFunctionOperationsListener = (
857850 message : MessageValue < Response > ,
@@ -1002,6 +995,22 @@ export abstract class AbstractPool<
1002995 : new Error ( `Task '${ taskName } ' id '${ taskId } ' aborted` )
1003996 }
1004997
998+ private getQueuedTasks ( ) : number {
999+ return this . workerNodes . reduce ( ( accumulator , workerNode ) => {
1000+ return accumulator + workerNode . usage . tasks . queued
1001+ } , 0 )
1002+ }
1003+
1004+ private getStealingWorkerNodes ( ) : number {
1005+ return this . workerNodes . reduce (
1006+ ( accumulator , _ , workerNodeKey ) =>
1007+ this . isWorkerNodeStealing ( workerNodeKey )
1008+ ? accumulator + 1
1009+ : accumulator ,
1010+ 0 ,
1011+ )
1012+ }
1013+
10051014 /**
10061015 * Gets task function worker choice strategy, if any.
10071016 *
@@ -1827,7 +1836,7 @@ export abstract class AbstractPool<
18271836 ! this . started ||
18281837 this . destroying ||
18291838 this . workerNodes . length <= 1 ||
1830- this . info . queuedTasks === 0
1839+ this . getQueuedTasks ( ) === 0
18311840 )
18321841 }
18331842
@@ -1976,7 +1985,7 @@ export abstract class AbstractPool<
19761985 private readonly isStealingRatioReached = ( ) : boolean => {
19771986 return (
19781987 this . opts . tasksQueueOptions ?. tasksStealingRatio === 0 ||
1979- ( this . info . stealingWorkerNodes ?? 0 ) >
1988+ this . getStealingWorkerNodes ( ) >
19801989 Math . ceil (
19811990 this . workerNodes . length *
19821991 this . opts . tasksQueueOptions ! . tasksStealingRatio ! ,
0 commit comments