Skip to content

Commit

Permalink
fix issue with closure within loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Nov 21, 2015
1 parent e932224 commit 5d0a058
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions main.go
Expand Up @@ -36,19 +36,20 @@ func main() {
errs := make(chan error)
var wg sync.WaitGroup

sniff := func(fileName string, hunk *diff.Hunk) {
errs <- func() error {
defer func() { wg.Done() }()
return hound.Sniff(fileName, hunk)
}()
}

for _, fileDiff := range fileDiffs {
fileName := fileDiff.NewName
hunks := fileDiff.GetHunks()

for _, hunk := range hunks {
wg.Add(1)

go func() {
errs <- func() error {
defer func() { wg.Done() }()
return hound.Sniff(fileName, hunk)
}()
}()
go sniff(fileName, hunk)
}
}

Expand Down

0 comments on commit 5d0a058

Please sign in to comment.