Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (23 sloc) 534 Bytes
package google
import (
"errors"
"time"
)
func SearchTimeout(query string, timeout time.Duration) ([]Result, error) { // HL
timer := time.After(timeout) // HL
c := make(chan Result, 3)
go func() { c <- Web(query) }()
go func() { c <- Image(query) }()
go func() { c <- Video(query) }()
var results []Result
for i := 0; i < 3; i++ {
select { // HL
case result := <-c: // HL
results = append(results, result)
case <-timer: // HL
return results, errors.New("timed out")
}
}
return results, nil
// STOP OMIT
}
You can’t perform that action at this time.