From 865b0a1c8875cebc236bc7dab8ba3867fffd43cf Mon Sep 17 00:00:00 2001 From: Meutel Date: Sat, 8 Jul 2017 15:15:28 +0200 Subject: [PATCH] Improved shared SHA dir --- shadirconcurrent/main.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/shadirconcurrent/main.go b/shadirconcurrent/main.go index c304b94..a03894a 100644 --- a/shadirconcurrent/main.go +++ b/shadirconcurrent/main.go @@ -6,10 +6,9 @@ import "io" import "log" import "os" import "path/filepath" -import "sync/atomic" +import "time" var chan_hash chan string -var running int32 func walk(path string, info os.FileInfo, err error) error { if err != nil { @@ -20,7 +19,6 @@ func walk(path string, info os.FileInfo, err error) error { if info.IsDir() { return nil } else { - atomic.AddInt32(&running, 1) go hash(info.Name(), path) } return nil @@ -54,10 +52,12 @@ func main() { if err := filepath.Walk(os.Args[1], walk); err != nil { panic(err) } - for str := range chan_hash { - fmt.Println(str) - atomic.AddInt32(&running, -1) - if running <= 0 { + + for { + select { + case str := <-chan_hash: + fmt.Println(str) + case <-time.After(10 * time.Millisecond): return } }