worker

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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