mirror of
https://github.com/hamburghammer/dll.git
synced 2025-03-07 07:45:56 +01:00
Change to gather the results for each file aynchronously
This commit is contained in:
parent
2310d1811f
commit
56fdc9c12a
1 changed files with 29 additions and 7 deletions
36
dll.go
36
dll.go
|
@ -6,6 +6,7 @@ import (
|
|||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type report struct {
|
||||
|
@ -84,16 +85,37 @@ func gather(source string, asFile bool) ([]*report, error) {
|
|||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintln(os.Stderr, "no source files supplied")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, source := range os.Args[1:] {
|
||||
r, err := gather(source, true)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing %s: %s\n", source, err)
|
||||
continue
|
||||
files := os.Args[1:]
|
||||
fileCount := len(files)
|
||||
rc := make(chan []*report, fileCount)
|
||||
|
||||
go func() {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(fileCount)
|
||||
|
||||
for _, source := range files {
|
||||
go func(source string) {
|
||||
defer wg.Done()
|
||||
r, err := gather(source, true)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing %s: %s\n", source, err)
|
||||
rc <- []*report{}
|
||||
return
|
||||
}
|
||||
rc <- r
|
||||
}(source)
|
||||
}
|
||||
for _, rep := range r {
|
||||
fmt.Println(rep)
|
||||
|
||||
wg.Wait()
|
||||
close(rc)
|
||||
}()
|
||||
|
||||
for reports := range rc {
|
||||
for _, report := range reports {
|
||||
fmt.Println(report)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue