MCPcopy
hub / github.com/lotusirous/go-concurrency-patterns / First

Function First

12-google3.0/main.go:30–39  ·  view source on GitHub ↗

How do we avoid discarding result from the slow server. We duplicates to many instance, and perform parallel request.

(query string, replicas ...Search)

Source from the content-addressed store, hash-verified

28// How do we avoid discarding result from the slow server.
29// We duplicates to many instance, and perform parallel request.
30func First(query string, replicas ...Search) Result {
31 c := make(chan Result)
32 for i := range replicas {
33 go func(idx int) {
34 c <- replicas[idx](query)
35 }(i)
36 }
37 // the magic is here. First function always waits for 1 time after receiving the result
38 return <-c
39}
40
41// I don't want to wait for slow server
42func Google(query string) []Result {

Callers 1

GoogleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected