```go
package main
import (
"fmt"
)
func main() {
chInt := make(chan int, 100)
for i := 0; i < 10; i++ {
chInt <- i
}
close(chInt)
chFlag := make(chan bool, 1)
defer close(chFlag)
go func() {
for {
select {
case v := <-chInt:
fmt.Println(v)
default:
chFlag <- true
return
}
}
}()
<-chFlag
}```
上面close(chInt) 为啥会导致select 一直在 case v := <-chInt:
fmt.Println(v) 死循环输出0 ,
删掉close(chInt) 或改成defer close(chInt) 就运行正常,符合预期
A receive operation on a closed channel can always proceed immediately, yielding the element type's zero value after any previously sent values have been received.
正解
#5