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.
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.