workerpool

package
v4.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPoolShuttingDown is returned when trying to submit a task to a shutting down pool
	ErrPoolShuttingDown = fmt.Errorf("worker pool is shutting down")

	// ErrQueueClosed is returned when trying to submit a task to a closed queue
	ErrQueueClosed = fmt.Errorf("queue is closed")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

type Option

type Option func(*Config)

func WithCancel

func WithCancel(cancel context.CancelFunc) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithQueueSize

func WithQueueSize(queueSize int) Option

func WithWorkers

func WithWorkers(workers int) Option

type Pool

type Pool interface {
	Submit(task Task) error
	Stop() error
	CloseQueue()
	BeforeShutdown(func() error)
	Wait()
}

func New

func New(name string, opts ...Option) Pool

New creates a new worker pool with the specified number of workers

type Task

type Task func(ctx context.Context) error

Task represents a unit of work that can return an error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL