parallel

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package parallel provides the bounded fail-fast parallel map used by safe's multi-path commands. It is internal so the concurrency helper never becomes public Vault-client API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CPULimit added in v1.21.1

func CPULimit() int

CPULimit returns the fan-out width for compute-bound work (RSA and SSH key generation): one worker per core, with a floor of 4 so small boxes still overlap generation with Vault round trips.

func EachLimit

func EachLimit[T any](ctx context.Context, items []T, limit int, fn func(ctx context.Context, i int, item T) error) error

EachLimit runs fn over items with at most limit concurrent calls. Fail-fast: after the first non-nil error no new item is dispatched, in-flight calls see their context cancelled, and the fan-out returns once they complete. Every failure is collected; a single failure is returned unwrapped so errors.As/Is classification behaves as in a sequential loop, and several come back as an *Errors that classifies by the first arrival only. A ctx the caller cancels stops dispatch the same way and is returned when no call failed on its own.

Cancellation bounds what fn lets it bound: an exec.CommandContext child is killed, but vaultkv requests carry no context (the client's 30 s timeout is their only cap) and rsa.GenerateKey cannot be interrupted mid-search, so those in-flight calls still run to completion.

func IOLimit added in v1.21.1

func IOLimit() int

IOLimit returns the fan-out width for network-bound work (gets, writes, imports, tree deletes and copies), where round-trip latency, not cores, is the constraint. SAFE_CONCURRENCY overrides the default, clamped to [1, 64]; an unset or unparseable value falls back to the default.

func NewErrors added in v1.21.1

func NewErrors(errs ...error) error

NewErrors folds collected failures into what EachLimit returns: nil for none, the bare error for one -- byte-identical output to a sequential loop -- and an *Errors for several. Callers pass only non-nil errors.

Types

type Errors added in v1.21.1

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

Errors collects every failure one EachLimit fan-out saw: the first arrival plus any in-flight siblings that failed before they could be cancelled. Error enumerates them all -- on a write command each one may name a partial write -- while Unwrap returns only the first, so errors.Is and errors.As classify a multi-failure run exactly as they classify its first failure alone.

func (*Errors) All added in v1.21.1

func (e *Errors) All(pred func(error) bool) bool

All reports whether pred holds for every collected failure. Suppression decisions (--force swallowing not-found errors) must consult every sibling: whichever error wins the arrival race says nothing about the others.

func (*Errors) Error added in v1.21.1

func (e *Errors) Error() string

func (*Errors) Unwrap added in v1.21.1

func (e *Errors) Unwrap() error

Unwrap returns the first failure only, never the whole slice: sibling failures are reported, not classified.

Jump to

Keyboard shortcuts

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