go select语句的用法和作用

package main

import(
	"time"
	"fmt"

)
func main() {
    //start := time.Now()
    ch1 := make(chan int)
    ch2 := make(chan int)

    go func() {
        time.Sleep(2 * time.Second)
        ch1 <- 3
    }()

    go func() {
        time.Sleep(3 * time.Second)
        ch2 <- 5
    }()

    fmt.Println("blocking on read...")
	select {
		case <-ch1:
			fmt.Printf("ch1 case...\n")
		case <-ch2:
			fmt.Printf("ch2 case...\n")
	}
}
上一篇:Go语言基础05(复合数据类型(上))


下一篇:GO channel的基础使用