File tree 1 file changed +11
-2
lines changed
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 5
5
"slices"
6
6
7
7
"github.com/nais/api/internal/workload"
8
+ "github.com/sourcegraph/conc/pool"
8
9
)
9
10
10
11
func ForWorkload (ctx context.Context , w workload.Workload ) * WorkloadStatus {
@@ -31,9 +32,17 @@ func ForWorkload(ctx context.Context, w workload.Workload) *WorkloadStatus {
31
32
}
32
33
33
34
func ForWorkloads [T workload.Workload ](ctx context.Context , workloads []T ) []WorkloadStatusError {
34
- var errs [ ]WorkloadStatusError
35
+ wg := pool . NewWithResults [[ ]WorkloadStatusError ](). WithContext ( ctx ). WithMaxGoroutines ( 10 )
35
36
for _ , workload := range workloads {
36
- errs = append (errs , ForWorkload (ctx , workload ).Errors ... )
37
+ wg .Go (func (ctx context.Context ) ([]WorkloadStatusError , error ) {
38
+ return ForWorkload (ctx , workload ).Errors , nil
39
+ })
40
+ }
41
+
42
+ errors , _ := wg .Wait ()
43
+ var errs []WorkloadStatusError
44
+ for _ , e := range errors {
45
+ errs = append (errs , e ... )
37
46
}
38
47
return errs
39
48
}
You can’t perform that action at this time.
0 commit comments