You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
479 B
Go
28 lines
479 B
Go
package nnet
|
|
|
|
import "github.com/panjf2000/ants/v2"
|
|
|
|
var pool *Pool
|
|
|
|
type Pool struct {
|
|
connPool *ants.Pool
|
|
workerPool *ants.Pool
|
|
}
|
|
|
|
func initPool(size int) {
|
|
p := &Pool{}
|
|
|
|
p.connPool, _ = ants.NewPool(size, ants.WithNonblocking(true))
|
|
p.workerPool, _ = ants.NewPool(size*2, ants.WithNonblocking(true))
|
|
|
|
pool = p
|
|
}
|
|
|
|
func (p *Pool) SubmitConn(h func()) error {
|
|
return p.connPool.Submit(h)
|
|
}
|
|
|
|
func (p *Pool) SubmitWorker(h func()) error {
|
|
return p.workerPool.Submit(h)
|
|
}
|