Skip to content

Commit 55386fc

Browse files
Changes from Xing Xing for the waitGroup.Done() call
1 parent 603e922 commit 55386fc

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

‎src/chapter2/search/feed/feed.go‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package feed
22

33
import (
44
"log"
5-
"sync"
65
)
76

87
type (
@@ -19,12 +18,7 @@ type (
1918
)
2019

2120
// Search pulls down each feed looking for the search term.
22-
func Search(matcher Matcher, searchTerm string, results chan Result, waitGroup *sync.WaitGroup) {
23-
// Call done so we can report we are finished processing.
24-
defer func() {
25-
waitGroup.Done()
26-
}()
27-
21+
func Search(matcher Matcher, searchTerm string, results chan Result) {
2822
// Search the data for the search term.
2923
searchResults, err := matcher.Match(searchTerm)
3024
if err != nil {

‎src/chapter2/search/main.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ func main() {
4141
}
4242

4343
// Launch the goroutine to perform the search.
44-
go feed.Search(matcher, searchTerm, results, &waitGroup)
44+
go func() {
45+
defer waitGroup.Done()
46+
feed.Search(matcher, searchTerm, results)
47+
}()
4548
}
4649

4750
// Wait for everything to be processed.

0 commit comments

Comments
 (0)