Help us shape the future of Go! Take the 2026 Go Developer Survey

parallel

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package parallel provides utilities for parallel execution of operations.

Index

Constants

View Source
const DefaultLimit = 10

DefaultLimit is the default concurrency limit for parallel operations.

Variables

This section is empty.

Functions

func ExecuteMap

func ExecuteMap[K comparable, V any, R any](
	ctx context.Context,
	entries map[K]V,
	fn func(ctx context.Context, key K, value V) (R, error),
) map[K]*Result[R]

ExecuteMap runs fn for each key-value pair in entries concurrently. Results are collected in a map keyed by the same keys as entries. Individual errors are captured in Result.Err rather than failing the entire operation.

func ExecuteMapWithLimit

func ExecuteMapWithLimit[K comparable, V any, R any](
	ctx context.Context,
	entries map[K]V,
	limit int,
	fn func(ctx context.Context, key K, value V) (R, error),
) map[K]*Result[R]

ExecuteMapWithLimit is like ExecuteMap but with a custom concurrency limit. A non-positive limit falls back to DefaultLimit: errgroup.SetLimit(0) uses a zero-capacity semaphore that would block the first g.Go forever (a deadlock), so it is never passed through.

Types

type Result

type Result[T any] struct {
	Value T
	Err   error
}

Result holds the result of a parallel operation.

Jump to

Keyboard shortcuts

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