Skip to content

Commit b3c8eec

Browse files
committed
use goroutines
1 parent aa3459e commit b3c8eec

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

find_replace.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"strings"
10+
"sync"
1011
"time"
1112
)
1213

@@ -67,19 +68,27 @@ func (fr *findReplace) WalkDir(f *File) {
6768
// complete, the file is renamed (if necessary) since no subsequent operations
6869
// will need to access it again.
6970
func (fr *findReplace) HandleFile(f *File) {
71+
var wg sync.WaitGroup
72+
7073
// If file is a directory, recurse immediately (depth-first).
7174
if f.Info().IsDir() {
7275
// Ignore certain directories
7376
if f.Base() == ".git" {
7477
return
7578
}
7679

77-
fr.WalkDir(f)
80+
wg.Add(1)
81+
go func() {
82+
defer wg.Done()
83+
fr.WalkDir(f)
84+
}()
7885
} else {
7986
// Replace the contents of regular files
8087
fr.ReplaceContents(f)
8188
}
8289

90+
wg.Wait() // for (potentially recursive) WalkDir calls to return
91+
8392
// Rename the file now that we're otherwise done with it
8493
fr.RenameFile(f)
8594
}

0 commit comments

Comments
 (0)