美文网首页
channel 到处隐藏panic

channel 到处隐藏panic

作者: anthonydan | 来源:发表于2020-03-16 22:27 被阅读0次

channel 到处隐藏panic

package main

import (
"fmt"
)

func main() {
//done := make(chan int)
//go func() {
// done <- 1
// fmt.Println("goroutine over")
//}()
//
//time.Sleep(1*time.Second)
//var t int
//var ok bool
//for i := 1; i <= 2; i++ {
// t, ok = <-done
// fmt.Println(i, ":", t, ok)
// if ok == false {
// break
// }
//
//}
//close(done)
//t, ok = <-done
//fmt.Println(":", t, ok)
////t, ok = <-done
//fmt.Println(":", t, ok)
//close(done)

c := make(chan int, 10)
c <- 123
//close(c)

var res int
var ok bool

res, ok = <-c
fmt.Println(res, ok)

res, ok = <-c
fmt.Println(res, ok) //此时ok为false

}

相关文章

网友评论

      本文标题:channel 到处隐藏panic

      本文链接:https://www.haomeiwen.com/subject/frcaehtx.html