mirror of
https://github.com/golang/go
synced 2024-11-22 01:14:40 -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:
parent
108564dabc
commit
35cee9f5d8
@ -158,21 +158,16 @@ func (v fileVisitor) VisitFile(path string, f *os.FileInfo) {
|
|||||||
|
|
||||||
|
|
||||||
func walkDir(path string) {
|
func walkDir(path string) {
|
||||||
// start an error handler
|
|
||||||
done := make(chan bool)
|
|
||||||
v := make(fileVisitor)
|
v := make(fileVisitor)
|
||||||
go func() {
|
go func() {
|
||||||
for err := range v {
|
filepath.Walk(path, v, v)
|
||||||
if err != nil {
|
close(v)
|
||||||
report(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
done <- true
|
|
||||||
}()
|
}()
|
||||||
// walk the tree
|
for err := range v {
|
||||||
filepath.Walk(path, v, v)
|
if err != nil {
|
||||||
close(v) // terminate error handler loop
|
report(err)
|
||||||
<-done // wait for all errors to be reported
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user