File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -366,7 +366,7 @@ export class ThreadPool extends EventEmitter {
366366 async stopThread ( thread , reason ) {
367367 const exitCode = await thread . stop ( )
368368 this . freeThreads . splice ( this . freeThreads . indexOf ( thread ) , 1 )
369- this . threads . splice ( this . freeThreads . indexOf ( thread ) , 1 )
369+ this . threads . splice ( this . threads . indexOf ( thread ) , 1 )
370370 return { pool : this . name , id : thread . id , exitCode, reason }
371371 }
372372
@@ -450,8 +450,16 @@ export class ThreadPool extends EventEmitter {
450450 return this
451451 }
452452
453- growPool ( ) {
454- if ( this . capacityAvailable ( ) ) return this . startThread ( )
453+ async growPool ( ) {
454+ if ( this . capacityAvailable ( ) ) {
455+ const thread = await this . startThread ( )
456+ if ( this . capacityAvailable ( ) )
457+ broker . on ( this . growPool . name , this . growPool , {
458+ singleton : true ,
459+ once : true
460+ } )
461+ return thread
462+ }
455463 }
456464
457465 jobQueueRate ( ) {
@@ -588,6 +596,11 @@ export class ThreadPool extends EventEmitter {
588596 )
589597 return thread
590598 }
599+ // none free, try to allocate
600+ const thread = this . allocate ( )
601+ // pop this one
602+ if ( thread ) this . freeThreads . pop ( )
603+ // dont return tyhread, let queued jobs go
591604 }
592605
593606 checkin ( thread ) {
You can’t perform that action at this time.
0 commit comments