Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

improve concurrency in the checkPaths function #267

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,8 @@ func checkPaths(c *errcheck.Checker, paths ...string) (errcheck.Result, error) {
if err != nil {
return errcheck.Result{}, err
}
// Check for errors in the initial packages.

work := make(chan *packages.Package, len(pkgs))
for _, pkg := range pkgs {
if len(pkg.Errors) > 0 {
return errcheck.Result{}, fmt.Errorf("errors while loading package %s: %v", pkg.ID, pkg.Errors)
}
work <- pkg
}
close(work)

var wg sync.WaitGroup
result := &errcheck.Result{}
Expand All @@ -164,6 +157,15 @@ func checkPaths(c *errcheck.Checker, paths ...string) (errcheck.Result, error) {
}()
}

// Check for errors in the initial packages.
for _, pkg := range pkgs {
if len(pkg.Errors) > 0 {
return errcheck.Result{}, fmt.Errorf("errors while loading package %s: %v", pkg.ID, pkg.Errors)
}
work <- pkg
}
close(work)

wg.Wait()
return result.Unique(), nil
}
Expand Down