⚙️ Configuration
When creating a new workers controller, you can customize its behavior through the workers.Config
struct.
🛠 Config Fields
Field | Type | Description | Default |
---|---|---|---|
MaxWorkers | int | Maximum number of workers in the pool. If set to 0 , the pool size is dynamic. | 0 |
StartImmediately | bool | If true , tasks are executed immediately after being added. If false , tasks must be started manually via Start() . See Tasks for details. | false |
StopOnError | bool | If true , workers stop executing tasks on the first error encountered. If false , execution continues. See Results for details. | false |
TasksBufferSize | int | Buffer 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
)
- Dynamic pool (