github.com/wangyougui/gf/v2@v2.6.5/os/grpool/grpool_supervisor.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package grpool
     8  
     9  import (
    10  	"context"
    11  
    12  	"github.com/wangyougui/gf/v2/os/gtimer"
    13  )
    14  
    15  // supervisor checks the job list and fork new worker goroutine to handle the job
    16  // if there are jobs but no workers in pool.
    17  func (p *Pool) supervisor(_ context.Context) {
    18  	if p.IsClosed() {
    19  		gtimer.Exit()
    20  	}
    21  	if p.list.Size() > 0 && p.count.Val() == 0 {
    22  		var number = p.list.Size()
    23  		if p.limit > 0 {
    24  			number = p.limit
    25  		}
    26  		for i := 0; i < number; i++ {
    27  			p.checkAndForkNewGoroutineWorker()
    28  		}
    29  	}
    30  }