Documentation ¶
Overview ¶
Package parallel provides higher-order functions that run in parallel. Maximum concurrency may be restricted for all the functions.
Context cancellation: If the input context is canceled, MapBounded* will immediately stop mapping any new items, wait for workers running to exit, then return the context error.
Index ¶
- func MapBoundedErrgroup[S ~[]T, T, R any](ctx context.Context, list S, f func(int, T) R, workers int) (result []R, err error)
- func MapBoundedPool[S ~[]T, T, R any](ctx context.Context, list S, f func(int, T) R, workers int) (result []R, err error)
- func MapBoundedPoolErrgroup[S ~[]T, T, R any](ctx context.Context, list S, f func(int, T) R, workers int) (result []R, err error)
- func MapBoundedPoolLockfree[S ~[]T, T, R any](ctx context.Context, list S, f func(int, T) R, workers int) (result []R, err error)
- func MapBoundedSema[S ~[]T, T, R any](ctx context.Context, list S, f func(int, T) R, inflight int) (result []R, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapBoundedErrgroup ¶
func MapBoundedErrgroup[S ~[]T, T, R any]( ctx context.Context, list S, f func(int, T) R, workers int, ) (result []R, err error)
MapBoundedErrgroup maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a maximum of inflight workers. An errgroup.Group is used to coordinate them.
func MapBoundedPool ¶
func MapBoundedPool[S ~[]T, T, R any]( ctx context.Context, list S, f func(int, T) R, workers int, ) (result []R, err error)
MapBoundedPool maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a fixed-size pool of workers.
func MapBoundedPoolErrgroup ¶
func MapBoundedPoolErrgroup[S ~[]T, T, R any]( ctx context.Context, list S, f func(int, T) R, workers int, ) (result []R, err error)
MapBoundedPoolErrgroup maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a fixed-size pool of workers. An errgroup.Group is used to coordinate them.
func MapBoundedPoolLockfree ¶
func MapBoundedPoolLockfree[S ~[]T, T, R any]( ctx context.Context, list S, f func(int, T) R, workers int, ) (result []R, err error)
MapBoundedPoolLockfree maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a fixed-size pool of workers. No channels or locks are involved in the dispatch process.
Types ¶
This section is empty.