标签:sed sleep second int func make closed printf cas
func Test_chanel(t *testing.T) {
c := make(chan int, 1)
go func() {
time.Sleep(time.Second * 3)
close(c)
}()
for {
select {
case i := <-c:
log.Printf("chan is closed, value is [%v]", i)
}
}
}
close的channel, 从里面可以一直取到值,不过是默认值,具体值取决于类型。
标签:sed sleep second int func make closed printf cas
原文地址:https://www.cnblogs.com/zhouj-happy/p/11209924.html