mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
31 lines
741 B
Go
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/v2/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()
|
|
}
|
|
}
|
|
}
|