Documentation
¶
Overview ¶
Package workerpool provides a generic buffered worker pool: items submitted via Submit are fanned out across a fixed number of worker goroutines, each running the handler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStopped = errors.New("workerpool: stopped")
ErrStopped is returned by Submit when the pool is stopped.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options)
func WithCapacity ¶
WithCapacity sets the number of items buffered before Submit blocks.
func WithRateLimit ¶
WithRateLimit caps how fast items are handled across all workers.
func WithWorkers ¶
WithWorkers sets the number of goroutines running the handler.
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
func (*Pool[T]) Stop ¶
Stop rejects new submissions, handles buffered items and waits for the workers to finish. If ctx is done first, its error is returned and workers may still be running; calling Stop again waits again.
func (*Pool[T]) Submit ¶
Submit enqueues value, blocking while the buffer is full. ctx's values reach the handler but its cancellation doesn't, so processing isn't aborted when the caller's ctx ends. It returns ErrStopped if the pool is stopped, or ctx's error if ctx is done before value is enqueued.