You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
511 B

package main
import (
"fmt"
"time"
)
func main() {
c1 := make(chan string, 1)
go func() {
time.Sleep(5 * time.Second)
c1 <- "channel 1 response!"
}()
select {
case res := <-c1:
fmt.Println(res)
case <-time.After(3 * time.Second):
fmt.Println("channel 1 timeout!")
}
c2 := make(chan string, 1)
go func() {
time.Sleep(2 * time.Second)
c2 <- "channel 2 response!"
}()
select {
case res := <-c2:
fmt.Println(res)
case <-time.After(3 * time.Second):
fmt.Println("timeout 2")
}
}