replication too

This commit is contained in:
Stephen McQuay 2013-05-14 21:20:10 -07:00
parent f3794ba244
commit 530ac5a0e5

View File

@ -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++ {