This commit is contained in:
expvintl
2025-02-21 20:28:02 +08:00
commit 6e5b3875f9
7 changed files with 229 additions and 0 deletions

27
utils/goroutine_pool.go Normal file
View File

@ -0,0 +1,27 @@
package utils
import (
"fmt"
"sync"
"github.com/panjf2000/ants"
)
type PoolInfo struct {
Pool *ants.Pool
MaxWorkers int
TaskWaitGroup sync.WaitGroup
}
func (pool *PoolInfo) NewPool(num int) {
p, err := ants.NewPool(num)
if err != nil {
fmt.Println("Create Pool Error:", err)
return
}
pool.Pool = p
pool.MaxWorkers = num
}
func (pool *PoolInfo) AddTask(fun func()) {
pool.Pool.Submit(fun)
}