Documentation
¶
Index ¶
Constants ¶
This section is empty.
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 WithIdleTimeout ¶
WithIdleTimeout set idle timeout, default is 1s. if idle timeout is less than 1s, it will be set to 1s. worker routine will be closed if no task received in idle timeout. if new task received, new worker will be created.
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 blocking, waiting all tasks be executed and no tasks to execute in idle timeout(default 1s), then stop the pool, if taskChan never empty, it wouldn't return.
func (*Pool) WaitTimeout ¶
WaitTimeout waiting with worker idle timeout, then stop the pool. if taskChan never empty, it wouldn't return.