Documentation ¶
Index ¶
- type RunFunc
- type WorkerPool
- func (w *WorkerPool) Busy() int
- func (w *WorkerPool) Excess() int
- func (w *WorkerPool) Run(data ...interface{})
- func (w *WorkerPool) ScaleDown(newSize int) error
- func (w *WorkerPool) ScaleTo(newSize int) error
- func (w *WorkerPool) ScaleUp(newSize int) error
- func (w *WorkerPool) Size() int
- func (w *WorkerPool) Stop()
- func (w *WorkerPool) StopAndCount()
- func (w *WorkerPool) Waiting() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
func NewBufferedPool ¶
func NewBufferedPool(size, bufSize int, run RunFunc) *WorkerPool
Create a new WorkerPool with an initial worker count and job buffer size
The job buffer allows new jobs to be queued without blocking if all the workers are busy
Panics when size < 0
func NewPool ¶
func NewPool(size int, run RunFunc) *WorkerPool
Create a new WorkerPool with an initial worker count
Panics when size < 0
func (*WorkerPool) Busy ¶
func (w *WorkerPool) Busy() int
Get the number of busy workers in this WorkerPool
func (*WorkerPool) Excess ¶ added in v1.0.2
func (w *WorkerPool) Excess() int
Get the number of workers waiting to close in this WorkerPool
func (*WorkerPool) ScaleDown ¶
func (w *WorkerPool) ScaleDown(newSize int) error
Scale the WorkerPool down to a new specified size
Blocks until all workers have been stopped. Safe to run in the background.
func (*WorkerPool) ScaleTo ¶ added in v1.0.2
func (w *WorkerPool) ScaleTo(newSize int) error
Resize the WorkerPool by scaling up or down to accommodate a new size
func (*WorkerPool) ScaleUp ¶
func (w *WorkerPool) ScaleUp(newSize int) error
Scale the WorkerPool up to a new specified size
Safe to run in the background.
func (*WorkerPool) Size ¶
func (w *WorkerPool) Size() int
Get the total number of workers in this WorkerPool
func (*WorkerPool) Stop ¶
func (w *WorkerPool) Stop()
Stop the WorkerPool by closing all channels and stopping all workers
func (*WorkerPool) StopAndCount ¶ added in v1.0.2
func (w *WorkerPool) StopAndCount()
Stop the WorkerPool and keep track of the channels waiting to close by sending a closing signal to each worker. Slower than Stop()
Blocks until all workers that were running have been closed. Workers stopped due to down-scaling do not cause this function to block.
func (*WorkerPool) Waiting ¶ added in v1.0.2
func (w *WorkerPool) Waiting() int
Get the number of workers currently waiting for jobs
Equivalent to Size() - Busy()