Commit 02ccb33b authored by Charlie Getzen's avatar Charlie Getzen

use WaitGroup instead of channels and counters

Signed-off-by: 's avatarCharlie Getzen <charlie.getzen@procore.com>
parent 8dd89867
......@@ -26,6 +26,7 @@ import (
"log"
"sort"
"strings"
"sync"
"time"
"k8s.io/apimachinery/pkg/api/meta"
......@@ -563,27 +564,18 @@ func perform(infos Result, fn ResourceActorFunc) error {
}
func batchPerform(infos Result, fn ResourceActorFunc, errs chan<- error) {
if len(infos) == 0 {
return
}
finished := make(chan bool, 10000)
kind := infos[0].Object.GetObjectKind().GroupVersionKind().Kind
counter := 0
var kind string
var wg sync.WaitGroup
for _, info := range infos {
currentKind := info.Object.GetObjectKind().GroupVersionKind().Kind
if kind != currentKind {
// Wait until the previous kind has finished
for i := 0; i < counter; i++ {
<-finished
}
counter = 0
wg.Wait()
kind = currentKind
}
counter = counter + 1
wg.Add(1)
go func(i *resource.Info) {
errs <- fn(i)
finished <- true
wg.Done()
}(info)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment