worker

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParallelChunkMap added in v0.58.2

func ParallelChunkMap[T any, R any](
	ctx context.Context,
	items []T,
	workerFunc func(ctx context.Context, workerIdx int, chunk []T, onProcessed func(int)) (R, error),
	onProgress ProgressCallback,
	opts ProgressOptions,
) ([]R, error)

ParallelChunkMap partitions the given slice into chunks across worker goroutines, executes workerFunc concurrently with errorgroup, and periodically reports progress.

Types

type Pool

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

Pool enables running a goroutine with max parallel count limit.

func NewPool

func NewPool(maxParallelCount int) *Pool

func (*Pool) Run

func (t *Pool) Run(f func())

func (*Pool) Wait

func (t *Pool) Wait()

type ProgressCallback added in v0.58.2

type ProgressCallback func(progressPercentage float64, message string) error

ProgressCallback receives streaming progress percentage (in [0.0, 1.0] or a mapped range) and a message.

type ProgressOptions added in v0.58.2

type ProgressOptions struct {
	// Interval is the interval between periodic progress updates. Defaults to 1s if <= 0.
	Interval time.Duration
	// MessageFmt is the template for progress messages (e.g. "Processing (%d/%d)...").
	MessageFmt string
	// MinProgress is the starting progress percentage for this step (e.g. 0.0).
	MinProgress float64
	// MaxProgress is the ending progress percentage for this step (e.g. 1.0).
	MaxProgress float64
	// NumWorkers overrides the number of parallel workers. Defaults to GOMAXPROCS if <= 0.
	NumWorkers int
}

ProgressOptions defines configuration for progress reporting in parallel operations.

Jump to

Keyboard shortcuts

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