blob: eff5c20cf3cb64c4bacc717aa1af249309dc994a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package pool
import (
"runtime"
"golang.org/x/sync/errgroup"
)
func Run[T any](items []T, fn func(T) error) error {
if len(items) == 0 {
return nil
}
g := &errgroup.Group{}
g.SetLimit(runtime.NumCPU())
for _, item := range items {
g.Go(func() error { return fn(item) })
}
return g.Wait()
}
|