use WaitGroup instead of channels and counters

Signed-off-by: Charlie Getzen <charlie.getzen@procore.com>
pull/6571/head
Charlie Getzen 5 years ago
parent 25bbd88639
commit ce4ca05d0a

@ -23,6 +23,7 @@ import (
"io" "io"
"log" "log"
"strings" "strings"
"sync"
"time" "time"
jsonpatch "github.com/evanphx/json-patch" jsonpatch "github.com/evanphx/json-patch"
@ -286,27 +287,18 @@ func perform(infos ResourceList, fn func(*resource.Info) error) error {
} }
func batchPerform(infos Result, fn ResourceActorFunc, errs chan<- error) { func batchPerform(infos Result, fn ResourceActorFunc, errs chan<- error) {
if len(infos) == 0 { var kind string
return var wg sync.WaitGroup
}
finished := make(chan bool, 10000)
kind := infos[0].Object.GetObjectKind().GroupVersionKind().Kind
counter := 0
for _, info := range infos { for _, info := range infos {
currentKind := info.Object.GetObjectKind().GroupVersionKind().Kind currentKind := info.Object.GetObjectKind().GroupVersionKind().Kind
if kind != currentKind { if kind != currentKind {
// Wait until the previous kind has finished wg.Wait()
for i := 0; i < counter; i++ {
<-finished
}
counter = 0
kind = currentKind kind = currentKind
} }
counter = counter + 1 wg.Add(1)
go func(i *resource.Info) { go func(i *resource.Info) {
errs <- fn(i) errs <- fn(i)
finished <- true wg.Done()
}(info) }(info)
} }
} }

Loading…
Cancel
Save