Skip to content

Commit

Permalink
refactor: Removing use of sync.WaitGroup in favor of done chan
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed May 23, 2021
1 parent 4824d72 commit d4c960a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/url"
"runtime"
"strings"
"sync"

"github.com/ViBiOh/httputils/v4/pkg/flags"
"github.com/ViBiOh/httputils/v4/pkg/httpjson"
Expand Down Expand Up @@ -81,12 +80,11 @@ func (a app) LatestVersions(repository string, patterns []string) (map[string]se
return nil, fmt.Errorf("unable to fetch tags: %s", err)
}

var wg sync.WaitGroup
done := make(chan struct{})
versionsStream := make(chan interface{}, runtime.NumCPU())

wg.Add(1)
go func() {
defer wg.Done()
defer close(done)

for tag := range versionsStream {
tagVersion, err := semver.Parse(*(tag.(*string)))
Expand All @@ -104,7 +102,7 @@ func (a app) LatestVersions(repository string, patterns []string) (map[string]se
return nil, fmt.Errorf("unable to read tags: %s", err)
}

wg.Wait()
<-done

return versions, nil
}
Expand Down

0 comments on commit d4c960a

Please sign in to comment.