# README

Worker pool

Similar to a thread pool in Java, a worker pool is a fixed-size pool of goroutines that can execute any kind of tasks as they come. When the number of tasks grows larger than the number of available workers, new tasks will be pushed into a waiting queue to be executed later.

Our implementation is an upgrade/retrofit of the popular https://github.com/gammazero/workerpool repo to match the behaviors of other features in this library.

wp := NewWorkerPool(
    WithMaxSize(5), 
	WithBurst(10, 5), 
)
defer wp.Stop()

task := NewTask(func(context.Context) (animal, error) {
    // run the job
    return res, err
})

ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

// The given context will be used to execute the task
wp.Submit(ctxWithTimeout, task)

// Block and wait for the outcome
result, err := task.Outcome()

# Functions

NewWorkerPool creates and starts a pool of worker goroutines.
WithBurst sets the threshold for the waiting queue at which point the maximum size of the worker pool will be increased by the given capacity.
WithIdleTimeout sets the maximum duration that a worker can stay idle before one of them gets killed.
WithMaxSize sets the maximum size of the worker pool under normal condition.

# Structs

WorkerPool is similar to a thread pool in Java, where the number of concurrent goroutines processing requests does not exceed the configured maximum.

# Type aliases

No description provided by the author