Documentation ¶
Index ¶
- Constants
- Variables
- func Cap() int
- func Free() int
- func Release()
- func Running() int
- func Submit(task func()) error
- type Option
- func WithExpiryDuration(expiryDuration time.Duration) Option
- func WithMaxBlockingTasks(maxBlockingTasks int) Option
- func WithNonblocking(nonblocking bool) Option
- func WithOptions(options Options) Option
- func WithPanicHandler(panicHandler func(interface{})) Option
- func WithPreAlloc(preAlloc bool) Option
- type Options
- type Pool
- type PoolWithFunc
Constants ¶
View Source
const ( // DEFAULT_ANTS_POOL_SIZE is the default capacity for a default goroutine pool. DEFAULT_ANTS_POOL_SIZE = math.MaxInt32 // DEFAULT_CLEAN_INTERVAL_TIME is the interval time to clean up goroutines. DEFAULT_CLEAN_INTERVAL_TIME = 1 // CLOSED represents that the pool is closed. CLOSED = 1 )
Variables ¶
View Source
var ( // ErrInvalidPoolSize will be returned when setting a negative number as pool 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") )
Functions ¶
Types ¶
type Option ¶ added in v1.3.0
type Option func(opts *Options)
func WithExpiryDuration ¶ added in v1.3.0
func WithMaxBlockingTasks ¶ added in v1.3.0
func WithNonblocking ¶ added in v1.3.0
func WithOptions ¶ added in v1.3.0
func WithPanicHandler ¶ added in v1.3.0
func WithPanicHandler(panicHandler func(interface{})) Option
func WithPreAlloc ¶ added in v1.3.0
type Options ¶ added in v1.3.0
type Options struct { // ExpiryDuration set the expired time (second) of every worker. ExpiryDuration time.Duration // PreAlloc indicate whether to make memory pre-allocation when initializing Pool. PreAlloc bool // Max number of goroutine blocking on pool.Submit. // 0 (default value) means no such limit. MaxBlockingTasks int // When Nonblocking is true, Pool.Submit will never be blocked. // ErrPoolOverload will be returned when Pool.Submit cannot be done at once. // When Nonblocking is true, MaxBlockingTasks is inoperative. Nonblocking bool // PanicHandler is used to handle panics from each worker goroutine. // if nil, panics will be thrown out again from worker goroutines. PanicHandler func(interface{}) }
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool accept the tasks from client, it limits the total of goroutines to a given number by recycling goroutines.
type PoolWithFunc ¶
type PoolWithFunc struct {
// contains filtered or unexported fields
}
PoolWithFunc accept the tasks from client, it limits the total of goroutines to a given number by recycling goroutines.
func NewPoolWithFunc ¶
func NewPoolWithFunc(size int, pf func(interface{}), options ...Option) (*PoolWithFunc, error)
NewPoolWithFunc generates an instance of ants pool with a specific function.
func (*PoolWithFunc) Free ¶
func (p *PoolWithFunc) Free() int
Free returns a available goroutines to work.
func (*PoolWithFunc) Invoke ¶
func (p *PoolWithFunc) Invoke(args interface{}) error
Invoke submits a task to pool.
func (*PoolWithFunc) Running ¶
func (p *PoolWithFunc) Running() int
Running returns the number of the currently running goroutines.
func (*PoolWithFunc) Tune ¶
func (p *PoolWithFunc) Tune(size int)
Tune change the capacity of this pool.
Click to show internal directories.
Click to hide internal directories.