Documentation
¶
Overview ¶
Package pool provides pooled concurrency helpers such as a parallel Map function.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Map ¶
func Map[T any, R any](ctx context.Context, collection []T, iteratee func(context.Context, T, int) (R, error), opts ...option) ([]R, error)
Map manipulates a slice and transforms it to a slice of another type concurrently.
Example ¶
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
result, err := Map(ctx,
[]int{1, 2, 3, 4, 5},
func(ctx context.Context, element int, index int) (string, error) {
return fmt.Sprintf("element: %d", element), nil
}, WithWorkers(4))
if err != nil {
// ...
}
fmt.Printf("%v", result)
Output: [element: 1 element: 2 element: 3 element: 4 element: 5]
func WithWorkers ¶
func WithWorkers(count uint) option
WithWorkers defines how many workers will be used to process tasks at most.
Types ¶
Click to show internal directories.
Click to hide internal directories.