replication too
This commit is contained in:
parent
f3794ba244
commit
530ac5a0e5
17
search.go
17
search.go
@ -25,11 +25,22 @@ func fakeSearch(kind string) Search {
|
||||
}
|
||||
}
|
||||
|
||||
func First(query string, replicas ...Search) Result {
|
||||
c := make(chan Result)
|
||||
searchReplica := func(i int) {
|
||||
c <- replicas[i](query)
|
||||
}
|
||||
for i := range replicas {
|
||||
go searchReplica(i)
|
||||
}
|
||||
return <-c
|
||||
}
|
||||
|
||||
func Google(query string) (results []Result) {
|
||||
c := make(chan Result)
|
||||
go func() { c <- Web(query) }()
|
||||
go func() { c <- Image(query) }()
|
||||
go func() { c <- Video(query) }()
|
||||
go func() { c <- First(query, Web, Web) }()
|
||||
go func() { c <- First(query, Image, Image) }()
|
||||
go func() { c <- First(query, Video, Video) }()
|
||||
|
||||
timeout := time.After(80 * time.Millisecond)
|
||||
for i := 0; i < 3; i++ {
|
||||
|
Loading…
Reference in New Issue
Block a user