diff --git a/shadirconcurrent/main.go b/shadirconcurrent/main.go index e673806..ac5a975 100644 --- a/shadirconcurrent/main.go +++ b/shadirconcurrent/main.go @@ -28,34 +28,34 @@ func main() { chan_hash, chan_path := make(chan string), make(chan string) for i := 0; i < 100; i++ { + wg.Add(1) go func() { for path := range chan_path { if h, err := sha256File(path); err != nil { - wg.Done() log.Print("Error "+path, err) } else { chan_hash <- h } } + wg.Done() }() } - go func() { - for h := range chan_hash { - fmt.Println(h) - wg.Done() - } + wg.Wait() + close(chan_hash) }() - err := filepath.Walk(os.Args[1], func(path string, info os.FileInfo, err error) error { - if err == nil && !info.IsDir() { - wg.Add(1) - chan_path <- path - } - return err - }) - if err != nil { - log.Fatalln(err) + go func() { + filepath.Walk(os.Args[1], func(path string, info os.FileInfo, err error) error { + if err == nil && !info.IsDir() { + chan_path <- path + } + return err + }) + close(chan_path) + }() + + for h := range chan_hash { + fmt.Println(h) } - wg.Wait() }