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.