Documentation
¶
Overview ¶
Package work provides structured concurrency primitives with bounded parallelism and OpenTelemetry tracing. It offers Map, All, Race, and Stream patterns for fan-out/fan-in workloads.
Index ¶
- func All(ctx context.Context, tasks []func(context.Context) error, opts ...Option) error
- func Map[T, R any](ctx context.Context, items []T, fn func(context.Context, T) (R, error), ...) ([]R, error)
- func Race[R any](ctx context.Context, tasks ...func(context.Context) (R, error)) (R, error)
- func Stream[T, R any](ctx context.Context, in <-chan T, fn func(context.Context, T) (R, error), ...) <-chan Result[R]
- type Errors
- type Failure
- type Option
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Map ¶
func Map[T, R any](ctx context.Context, items []T, fn func(context.Context, T) (R, error), opts ...Option) ([]R, error)
Map applies fn to each item with bounded concurrency. Results are returned in input order. If any items fail, returns *Errors with all failures.
func Race ¶
Race launches all tasks concurrently and returns the result of the first one to succeed. If all tasks fail, returns *Errors. The context passed to tasks is cancelled once a winner is found.
func Stream ¶
func Stream[T, R any](ctx context.Context, in <-chan T, fn func(context.Context, T) (R, error), opts ...Option) <-chan Result[R]
Stream applies fn to values received from in with bounded concurrency, sending results to the returned channel. The output channel is closed when the input channel is closed and all in-flight work completes.
Types ¶
type Errors ¶
type Errors struct {
Failures []Failure
}
Errors collects per-item failures from Map or All.