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, } }