Documentation
¶
Overview ¶
Package task provides a global task scheduling pool and a task group.
It is built on the ants goroutine pool and supports concurrency control, error aggregation and graceful degradation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶ added in v2.6.0
func Add(task func())
Add runs task.
The task is submitted to the global task pool first; it degrades to running in a directly created goroutine when the pool is full or unavailable.
Types ¶
type Group ¶ added in v2.6.0
type Group struct {
// contains filtered or unexported fields
}
Group aggregates the errors of multiple tasks and supports context cancellation and a concurrency limit.
func WithContext ¶ added in v2.6.0
WithContext returns a new Group and a context derived from ctx.
The derived context is canceled with the first task error as its cause when the first task fails or when Wait returns.
func (*Group) Go ¶ added in v2.6.0
Go runs f as a task.
The task runs in the global task pool and is subject to the concurrency limit. When the task fails, its error is recorded if it is the first one and the context is canceled.
func (*Group) SetLimit ¶ added in v2.6.0
SetLimit sets the concurrency limit to n.
The limit must be set before any task is started. A negative n means no limit. Changing the limit while tasks are running panics.
type Option ¶
type Option func(o *options)
Option configures the task pool.
func WithDisablePurge ¶
WithDisablePurge returns an Option that sets whether purging is disabled.
When purging is disabled, idle goroutines are not reclaimed periodically.
func WithNonblocking ¶
WithNonblocking returns an Option that sets whether the pool is non-blocking.
In non-blocking mode, a task submission returns an error immediately when the pool is full instead of blocking and waiting.