Documentation ¶
Index ¶
- Constants
- Variables
- type Logger
- type Option
- func WithExpiryDuration(expiryDuration time.Duration) Option
- func WithLogger(logger Logger) Option
- func WithMaxBlockingTasks(maxBlockingTasks int) Option
- func WithNonblocking(nonblocking bool) Option
- func WithOptions(options *Options) Option
- func WithPanicHandle(panicHandle func(interface{})) Option
- func WithPreAlloc(preAlloc bool) Option
- type Options
- type Pool
- type WorkerStack
Constants ¶
View Source
const ( // DefaultAntsPoolSize is the default capacity for a default goroutine pool. DefaultAntsPoolSize = math.MaxInt32 // DefaultCleanIntervalTime is the interval time to clean up goroutines. DefaultCleanIntervalTime = time.Second )
View Source
const ( OPENED = iota CLOSED )
Variables ¶
View Source
var ( // ErrInvalidPoolSize will be returned when setting a negative number as pool capacity, this error will be only used // by pool with func because pool without func can be infinite by setting up a negative capacity. ErrInvalidPoolSize = errors.New("invalid size for pool") // ErrLackPoolFunc will be returned when invokers don't provide function for pool. ErrLackPoolFunc = errors.New("must provide function for pool") // ErrInvalidPoolExpiry will be returned when setting a negative number as the periodic duration to purge goroutines. ErrInvalidPoolExpiry = errors.New("invalid expiry for pool") // ErrPoolClosed will be returned when submitting task to a closed pool. ErrPoolClosed = errors.New("this pool has been closed") // ErrPoolOverload will be returned when the pool is full and no workers available. ErrPoolOverload = errors.New("too many goroutines blocked on submit or Nonblocking is set") // ErrInvalidPreAllocSize will be returned when trying to set up a negative capacity under PreAlloc mode. ErrInvalidPreAllocSize = errors.New("can not set up a negative capacity under PreAlloc mode") )
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger interface {
Printf(format string, args ...interface{})
}
Logger is used for logging formatted messages.
type Option ¶
type Option func(opts *Options)
Option 是一个函数 函数式编程
func WithExpiryDuration ¶
func WithLogger ¶
func WithMaxBlockingTasks ¶
func WithNonblocking ¶
func WithOptions ¶
func WithPanicHandle ¶
func WithPanicHandle(panicHandle func(interface{})) Option
func WithPreAlloc ¶
type Options ¶
type Options struct { //worker 过期时间 ExpiryDuration time.Duration //初始化pool时是否开辟内存,进行内存预分配 PreAlloc bool // goroutine阻塞池的最大数目。 // 0(默认值)表示没有这种限制。 MaxBlockingTasks int //从pool中获取goroutine是否是阻塞的,当为true时,不会阻塞,并且MaxBlockingTasks是无效的 Nonblocking bool //panic处理函数 // PanicHandler用于处理来自每个worker goroutine的恐慌。 //如果为nil, panic将再次从worker goroutines被抛出。 PanicHandle func(interface{}) //日志记录器是用于记录信息的自定义日志记录器,如果没有设置, //默认的标准日志从日志包使用。 Logger Logger }
Options包含在实例化一个ant池时应用的所有选项
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
pool 从客户端接收任务,回收goroutines来控制goroutines数量
type WorkerStack ¶
type WorkerStack struct {
// contains filtered or unexported fields
}
stack存储数据结构 一级缓存
Source Files ¶
Click to show internal directories.
Click to hide internal directories.