[web result for "golang", video result for "golang", image result for "golang"]
66.194887ms
Search with Timeout
We can make our search a bit more robust by introducing timeout because there's a chance that some results won't come back for a while and we don't want to wait for it.
Suppose we can make requests to make multiple slave/replica servers and only return searches that complete in under 80 milliseconds.
funcmultisearch(query string, replicas ...search) string { ch :=make(chanstring) searchReplica :=func(i int) { ch <-replicas[i](query) }for i :=range replicas {gosearchReplica(i) }// As soon as one of the replicas returns a result, return immediately.return<-ch}
Now we can make requests to multiple slave servers.