Skip to content

Commit cbdfd03

Browse files
author
gbbr
committed
Addressed Bill's comments and clarified option
1 parent 7b0ccd0 commit cbdfd03

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

chapter7/patterns/search/main/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func main() {
1616
// Submit the search and display the results.
1717
results := search.Submit(
1818
"golang",
19-
search.First,
19+
search.OnlyFirst,
2020
search.Google,
2121
search.Bing,
2222
search.Yahoo,

chapter7/patterns/search/search.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func Yahoo(s *searchSession) {
4040
s.searchers["yahoo"] = NewYahoo()
4141
}
4242

43-
func First(s *searchSession) { s.first = true }
43+
func OnlyFirst(s *searchSession) { s.first = true }
4444

4545
// Submit uses goroutines and channels to perform a search against the three
4646
// leading search engines concurrently.
@@ -67,7 +67,10 @@ func Submit(query string, options ...func(*searchSession)) []Result {
6767
// concurrently discarding the remaining searchResults.
6868
// Failing to do so will leave the Searchers blocked forever.
6969
if session.first && search > 0 {
70-
go log.Printf("search : Submit : Info : Results Discarded : Results[%d]\n", len(<-session.resultChan))
70+
go func() {
71+
r := <-session.resultChan
72+
log.Printf("search : Submit : Info : Results Discarded : Results[%d]\n", len(r))
73+
}()
7174
continue
7275
}
7376

0 commit comments

Comments
 (0)