Workerpool Library for Go
A simple and efficient worker pool implementation in Go for concurrent task execution.
Features
- Easy-to-use API for managing worker pools.
- Static sizing of the pool irrespective of workload.
- Flexible configuration options for controlling pool behavior.
- Optimized for performance.
Installation
go get github.com/veerakumarak/go-workerpool
Usage
package main
import (
"fmt"
"github.com/veerakumarak/go-workerpool"
)
func main() {
// Create a new worker pool with 5 workers.
pool := workerpool.New("default-pool", 10, 100)
// Add tasks to the pool.
for i := 0; i < 10; i++ {
taskID := i
pool.Submit(func() {
fmt.Printf("Task %d is being processed\n", taskID)
})
}
// Wait for all tasks to complete and pool to be shutdown.
pool.Shutdown()
fmt.Println("All tasks have completed.")
}
Configuration
The worker pool can be configured with the following options:
MaxWorkers: Maximum number of workers in the pool.
MaxQueueSize: Maximum size of the task queue.
Example:
poolName := "default-pool"
maxWorkers := 10
maxQueueSize := 100
pool := workerpool.New(poolName, maxWorkers, maxQueueSize)
Contributing
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.