Documentation ¶
Overview ¶
Package workerpool ...
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPoolClosed ... ErrPoolClosed = errors.New("pool closed") // ErrContextInterrupt ... ErrContextInterrupt = errors.New("context interrupt") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*WorkerPool)
Option represents an option that can be passed when instantiating a worker pool to customize it
func PanicHandler ¶
func PanicHandler(panicHandler func(interface{})) Option
PanicHandler allows to change the panic handler function of a worker pool
type WorkerPool ¶
type WorkerPool struct { // Configurable settings MaxWorkers int32 PanicHandler func(interface{}) // contains filtered or unexported fields }
WorkerPool ...
func NewWorkerPool ¶
func NewWorkerPool(maxWorkers int32, options ...Option) *WorkerPool
NewWorkerPool ... maxWorkers defines the maximum workers that can be execute tasks concurrently.
func (*WorkerPool) AddTask ¶
func (w *WorkerPool) AddTask(ctx context.Context, fn func()) error
AddTask sends a new goroutine to execute a task asynchronously. It will block when activeWorkers reached maximum config size. It takes context to interrupt the waiting.
func (*WorkerPool) Stop ¶
func (w *WorkerPool) Stop(ctx context.Context) error
Stop waits for all active workers finish then stop the workerpool. It takes context to interrupt the waiting. Once workerpool is closed, it can not be open again.
func (*WorkerPool) WaitForTaskCompleted ¶
func (w *WorkerPool) WaitForTaskCompleted()
WaitForTaskCompleted waits for all active workers finish