This is a simple and efficient goroutine pool. It refers to the design idea of ants and uses the object pool sync.Pool to reuse the worker. v2.x newly adds goroutine reuse (greatly optimizes memory allocation and recycling, and reduces GC pressure). It is a memory-friendly pool that limits the number of concurrent goroutines.
go get -u github.com/TDroyal/gpool
package main
import (
"fmt"
"github.com/TDroyal/gpool"
)
func main() {
pool, _ := gpool.NewPool(10)
pool.Submit(func() {
// submit your task func
fmt.Println("task")
})
}