refactoring SHA dir: close channels

This commit is contained in:
Meutel 2017-07-08 17:15:37 +02:00
parent 78d5ca23a3
commit e75afaf5e6

View File

@ -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()
}