workerpool

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package workerpool provides a generic worker pool for parallel processing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultWorkers

func DefaultWorkers() int

DefaultWorkers returns the default number of workers based on CPU count.

func ProcessAll

func ProcessAll[In, Out any](
	ctx context.Context,
	items []In,
	cfg Config,
	fn func(context.Context, In) (Out, error),
) ([]Out, []error)

ProcessAll runs fn concurrently over items using a pool of workers. It returns results in the same order as input items. The context controls cancellation; if cancelled, partial results are still returned.

func ProcessAllVoid

func ProcessAllVoid[In any](
	ctx context.Context,
	items []In,
	cfg Config,
	fn func(context.Context, In) error,
) []error

ProcessAllVoid runs fn concurrently over items without collecting results. Use this when you only care about errors or side effects.

Types

type Config

type Config struct {
	// Workers is the number of concurrent workers. Zero uses DefaultWorkers().
	Workers int
}

Config controls pool behavior.

func (Config) EffectiveWorkers

func (c Config) EffectiveWorkers(itemCount int) int

EffectiveWorkers returns the worker count, using default if not set.

type ItemResult

type ItemResult[T any] struct {
	Index  int
	Result T
	Error  error
}

ItemResult holds the result of processing a single item.

Jump to

Keyboard shortcuts

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