From 5a237532facd4f88e8a3f53ecad0ecbd6c51856c Mon Sep 17 00:00:00 2001 From: Meutel Date: Sat, 8 Jul 2017 17:19:48 +0200 Subject: [PATCH] Refactoring SHA dir: shorter --- shadirconcurrent/main.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/shadirconcurrent/main.go b/shadirconcurrent/main.go index ac5a975..514c1a2 100644 --- a/shadirconcurrent/main.go +++ b/shadirconcurrent/main.go @@ -24,12 +24,12 @@ func main() { log.Fatalln("Usage shadir file") } - var wg sync.WaitGroup chan_hash, chan_path := make(chan string), make(chan string) - for i := 0; i < 100; i++ { - wg.Add(1) - go func() { + go func() { // 100 routines hashing + var wg sync.WaitGroup + for i := 0; i < 100; i++ { + wg.Add(1) for path := range chan_path { if h, err := sha256File(path); err != nil { log.Print("Error "+path, err) @@ -38,14 +38,12 @@ func main() { } } wg.Done() - }() - } - go func() { + } wg.Wait() close(chan_hash) }() - go func() { + go func() { // walk through files filepath.Walk(os.Args[1], func(path string, info os.FileInfo, err error) error { if err == nil && !info.IsDir() { chan_path <- path