Remove main goroutine
@@ -162,15 +162,13 @@ func deleteApps(cluster *kubernetes.Cluster, gitea *gitea.Client, org string) er
return err
}
+ // create a buffer, so there is no more than 'maxConcurrent' goroutines running at the same time
const maxConcurrent = 100
+ buffer := make(chan struct{}, maxConcurrent)
errChan := make(chan error, maxConcurrent)
- success := make(chan bool)
- stop := make(chan bool)
-
- go func() {
var wg sync.WaitGroup
- // create a buffer, so there is no more than 'maxConcurrent' goroutines running at the same time
- buffer := make(chan struct{}, maxConcurrent)
+ var forLoopErr error
+
loop:
for _, app := range apps {
buffer <- struct{}{}
@@ -188,21 +186,21 @@ func deleteApps(cluster *kubernetes.Cluster, gitea *gitea.Client, org string) er
}(app)
select {
- case <-stop:
+ case forLoopErr = <-errChan:
break loop
default:
}
}
wg.Wait()
- success <- true
- }()
- //wait until all apps are deleted or we get an error
+ if forLoopErr != nil {
+ return forLoopErr
+ }
+
select {
case err := <-errChan:
- stop <- true
return err
- case <-success:
+ default:
return nil
}
