其他分享
首页 > 其他分享> > go select语句的用法和作用

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")
	}
}

标签:语句,int,chan,ch2,ch1,Second,time,go,select
来源: https://blog.csdn.net/qq_31442743/article/details/118256457