1
0
mirror of https://github.com/golang/go synced 2024-11-25 04:07:55 -07:00

gofmt: simpler walkDir

Swapping the goroutines lets them reuse the
communication completion on v instead of
needing a second channel (done).

R=gri
CC=golang-dev
https://golang.org/cl/4287045
This commit is contained in:
Russ Cox 2011-03-15 14:04:47 -04:00
parent 108564dabc
commit 35cee9f5d8

View File

@ -158,21 +158,16 @@ func (v fileVisitor) VisitFile(path string, f *os.FileInfo) {
func walkDir(path string) {
// start an error handler
done := make(chan bool)
v := make(fileVisitor)
go func() {
for err := range v {
if err != nil {
report(err)
}
}
done <- true
filepath.Walk(path, v, v)
close(v)
}()
// walk the tree
filepath.Walk(path, v, v)
close(v) // terminate error handler loop
<-done // wait for all errors to be reported
for err := range v {
if err != nil {
report(err)
}
}
}