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.
ntool/npool/config.go

34 lines
965 B
Go

package npool
import (
"github.com/panjf2000/ants/v2"
"time"
)
type Config struct {
// PoolSize 连接池容量
PoolSize int `json:",default=2147483647"`
// ExpiryDuration 清理过期连接周期
ExpiryDuration time.Duration `json:",default=1s"`
// PreAlloc 为所有连接池预分配内存
PreAlloc bool `json:",default=false"`
// MaxBlockingTasks 最大阻塞任务数
MaxBlockingTasks int `json:",default=0"`
// Nonblocking 非阻塞goroutine申请新连接时若无可用goroutine则立即返回错误
Nonblocking bool `json:",default=false"`
// DisablePurge goroutine永远不会被清理
DisablePurge bool `json:",default=false"`
}
func (c Config) Options() ants.Options {
return ants.Options{
ExpiryDuration: c.ExpiryDuration,
PreAlloc: c.PreAlloc,
MaxBlockingTasks: c.MaxBlockingTasks,
Nonblocking: c.Nonblocking,
PanicHandler: nil,
Logger: nil,
DisablePurge: c.DisablePurge,
}
}