Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (26 sloc) 528 Bytes
package main
import (
"fmt"
"math/rand"
"time"
)
// START OMIT
func Query(boring string) string {
time.Sleep(time.Duration(rand.Intn(10)) * time.Second)
return boring + "!!!"
}
func main() {
start := time.Now()
defer func() { fmt.Printf("Got result in %.3f seconds\n", time.Since(start).Seconds()) }()
rand.Seed(time.Now().UnixNano())
c := make(chan string)
for i := 0; i < 10; i++ {
go func() { c <- Query("hello") }()
}
select {
case result := <-c:
fmt.Println("Result:", result)
return
}
}
// END OMIT
Something went wrong with that request. Please try again.