Files
gf/os/grpool/grpool_supervisor.go
John Guo 2cc4835c49 v2 -> v3
2025-04-10 14:12:35 +08:00

31 lines
741 B
Go

// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package grpool
import (
"context"
"github.com/gogf/gf/v3/os/gtimer"
)
// supervisor checks the job list and fork new worker goroutine to handle the job
// if there are jobs but no workers in pool.
func (p *Pool) supervisor(_ context.Context) {
if p.IsClosed() {
gtimer.Exit()
}
if p.list.Size() > 0 && p.count.Val() == 0 {
var number = p.list.Size()
if p.limit > 0 {
number = p.limit
}
for i := 0; i < number; i++ {
p.checkAndForkNewGoroutineWorker()
}
}
}