Skip to main content

⚙️ Configuration

When creating a new workers controller, you can customize its behavior through the workers.Config struct.

🛠 Config Fields

FieldTypeDescriptionDefault
MaxWorkersintMaximum number of workers in the pool. If set to 0, the pool size is dynamic.0
StartImmediatelyboolIf true, tasks are executed immediately after being added. If false, tasks must be started manually via Start(). See Tasks for details.false
StopOnErrorboolIf true, workers stop executing tasks on the first error encountered. If false, execution continues. See Results for details.false
TasksBufferSizeintBuffer size for pending tasks. Useful for controlling task queuing behavior. See Tasks for details.0

🧩 Example

Creating a controller with a fixed pool of 10 workers, immediate start, and custom buffer size:

w := workers.New[string](context.Background(), &workers.Config{
MaxWorkers: 10,
StartImmediately: true,
StopOnError: false,
TasksBufferSize: 1024,
})

📋 Notes

  • If no configuration is provided (nil), the controller defaults to:
    • Dynamic pool (MaxWorkers = 0)
    • Manual start (StartImmediately = false)
    • Continue on errors (StopOnError = false)
    • No task buffering (TasksBufferSize = 0)