parallel

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package parallel runs a per-input function under a bounded worker pool and returns results in the original input order. Used by sync, outdated, and sbom to fan out per-package work (recipe fetch, install, version probe) instead of serialising the inner loop.

Semantics:

  • Results are returned at the same index as their input.
  • Errors are positional, not aggregated — caller decides what counts as fatal.
  • One worker failing does NOT cancel peers. Callers that want short-circuit behaviour cancel the supplied context.
  • In-flight workers are not killed; they receive the cancelled context via their fn argument.
  • maxWorkers <= 0 is normalised to 1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEach

func ForEach[T any](ctx context.Context, inputs []T, maxWorkers int, fn func(context.Context, T) error) []error

ForEach is Map for callers that don't need a result slice (e.g. installers that report success via side effects).

func Map

func Map[T, R any](ctx context.Context, inputs []T, maxWorkers int, fn func(context.Context, T) (R, error)) ([]R, []error)

Map runs fn for each input concurrently, capped at maxWorkers in flight. Returns a result slice and an error slice, both indexed parallel to inputs.

Types

type Limiter added in v0.16.4

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

Limiter bounds the number of concurrent holders. Acquire blocks until a slot is free; Release frees one. A nil *Limiter is an unbounded no-op, so call sites can opt out without nil checks.

func NewLimiter added in v0.16.4

func NewLimiter(n int) *Limiter

NewLimiter returns a limiter that allows at most n concurrent holders. If n < 1 the limiter is unbounded: Acquire and Release are no-ops.

func (*Limiter) Acquire added in v0.16.4

func (l *Limiter) Acquire()

Acquire takes a slot, blocking until one is available. A nil limiter or an unbounded limiter returns immediately.

func (*Limiter) Cap added in v0.16.4

func (l *Limiter) Cap() int

Cap reports the configured concurrency ceiling. A nil or unbounded limiter reports 0 (no bound). Used by callers and tests that need to verify the limiter was sized as configured.

func (*Limiter) Release added in v0.16.4

func (l *Limiter) Release()

Release returns a slot. A nil limiter or an unbounded limiter is a no-op.

Jump to

Keyboard shortcuts

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