refactoring SHA dir: close channels
This commit is contained in:
parent
78d5ca23a3
commit
e75afaf5e6
@ -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() {
|
||||
wg.Wait()
|
||||
close(chan_hash)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for h := range chan_hash {
|
||||
fmt.Println(h)
|
||||
wg.Done()
|
||||
}
|
||||
}()
|
||||
|
||||
err := filepath.Walk(os.Args[1], func(path string, info os.FileInfo, err error) error {
|
||||
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)
|
||||
close(chan_path)
|
||||
}()
|
||||
|
||||
for h := range chan_hash {
|
||||
fmt.Println(h)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user