Tasks
✅ Tasks
Tasks are added to the queue using the Add()
method. Each task is passed as a function with one of the following signatures:
func(context.Context) R
func(context.Context) (R, error)
func(context.Context) error
where R
is the result type, matching the type parameter used when constructing the controller with workers.New()
.
📚 See Examples for practical usage examples.
🚀 Task Dispatch
- Tasks are assigned to workers after calling the
Start()
method. Start()
can be called manually or triggered automatically ifStartImmediately
is set totrue
in theworkers.Config
struct.
⚙️ Task Execution
- Once started, tasks are dispatched and assigned to available workers from the pool (see Types for more details).
- A worker executes its assigned task immediately.
- Task results and errors are returned through dedicated channels (see Results for details).
⚠️ Error Handling
- If
StopOnError
is enabled in the configuration, workers will stop executing new tasks upon encountering the first error. - If a panic occurs during task execution, it is safely recovered and sent as an error through the error channel.