Documentation
¶
Index ¶
Constants ¶
const WorkerIdleTimeoutToExit = time.Second
worker idle timeout to exit
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option defines pool options
func WithMaxTaskSize ¶
WithMaxTaskSize set max task size, default use runtime.NumCPU().
func WithMaxWorkers ¶
WithMaxWorkers set max worker routines, default is runtime.NumCPU().
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool worker routine pool
func (*Pool) AddTask ¶
AddTask add a task to Pool, the worker routine will execute the task. if task channel is full, it will be blocked.
func (*Pool) Start ¶
func (p *Pool) Start()
Start start routine pool in background. The initial number of workers is determined by the number of tasks in the channel and maxWorkers.
func (*Pool) StartN ¶
StartN start routine pool in background with workerNum initial workers. if workerNum <= 0 or workerNum > maxWorkers, it will be set to maxWorkers.
func (*Pool) Stop ¶
func (p *Pool) Stop()
Stop stop all routines no matter how many tasks wait for execution.
func (*Pool) Wait ¶
func (p *Pool) Wait()
Wait for blocking, and wait for all tasks to be executed and no tasks to be executed, then stop the pool. if taskChan never empty, it wouldn't return.
func (*Pool) WaitIdleTimeout ¶ added in v0.3.0
WaitIdleTimeout waiting with idle timeout, then stop the pool. if taskChan never empty, it wouldn't return.