MDGSF Software Engineer

[GO] select

2018-01-16
GO

package main

import "fmt"

var c1 = make(chan int, 1)
var c2 = make(chan string, 1)

func main() {

    c1 <- 1
    c2 <- "hello"

    select {

    case v1 := <-c1:
        fmt.Println(v1)

    case v2 := <-c2:
        panic(v2)

    }
}

可能执行到 v1,也可能执行到 v2。


weixingongzhonghao

上一篇 [GO] map for value

下一篇 [GO] slice

Comments

Content