Documentation
¶
Overview ¶
Package workerpool provides interfaces and utilities for managing goroutine pools.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a new Pool using the provided implementation-specific config file. The generic type parameter T specifies which interface the caller needs:
- Pool: basic pool operations only
- PoolWithStats: pool operations plus statistics (Running, Cap, Waiting, Stats)
- MultiPoolWithStats: multi-pool operations plus per-pool statistics
If no config is provided, a default config is chosen based on the requested interface T. Currently, ants is the default implementation which supports all pool types. If the requested pool type doesn't support the required interface, an error is returned.
Example usage:
// Default single pool
pool, err := workerpool.New[workerpool.Pool](ctx)
// Default single poolWithStats
pool, err := workerpool.New[workerpool.PoolWithStats](ctx)
// Default multipool
pool, err := workerpool.New[workerpool.MultiPool](ctx)
// Default multipool multipoolWithStats
pool, err := workerpool.New[workerpool.MultipoolWithStats](ctx)
// Basic pool with ants config
pool, err := workerpool.New[workerpool.Pool](ctx, ants.Config{NumWorkers: 10})
// Pool with stats
poolWithStats, err := workerpool.New[workerpool.PoolWithStats](ctx, ants.Config{
NumWorkers: 10,
PreAlloc: true,
NonBlocking: false,
})
// Multi-pool with stats
multiPool, err := workerpool.New[workerpool.MultiPoolWithStats](ctx, ants.MultiPoolConfig{
NumPools: 4,
NumWorkersPerPool: 10,
LoadBalancingStrategy: ants.RoundRobin,
})
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.