foreach

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package foreach provides bounded concurrent iteration. A fixed pool of worker goroutines processes tasks, so the goroutine count matches the concurrency limit rather than the task count.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concurrent

func Concurrent[T any](ctx context.Context, n int, maxWorkers int, fn func(ctx context.Context, i int) (T, error)) ([]T, error)

Concurrent executes fn for each index in [0, n) using at most maxWorkers concurrent goroutines. If maxWorkers is <= 0, it defaults to n (all tasks run concurrently). The context is checked before dispatching each task; cancelled contexts cause remaining tasks to return ctx.Err().

Results and errors are collected by index. The first error encountered does not cancel other tasks — all tasks run to completion or until the context is cancelled. The returned error is from the lowest-indexed failing task.

Types

This section is empty.

Jump to

Keyboard shortcuts

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