Skip to content

Commit e948d7e

Browse files
Fixed display loop and closed channel
1 parent 7594cf4 commit e948d7e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎src/chapter2/search/main.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ func main() {
2626

2727
// Wait for the result from each goroutine
2828
go func() {
29-
for {
30-
found := <-result
29+
for found := range result {
3130
log.Printf("%s:\n%s\n\n", found.Field, found.Content)
3231
}
3332
}()
@@ -55,4 +54,7 @@ func main() {
5554

5655
// Wait for everything to be processed.
5756
waitGroup.Wait()
57+
58+
// Close the channel and exit.
59+
close(result)
5860
}

0 commit comments

Comments
 (0)