golang 缓冲chan学习及使用
2019-04-10 本文已影响0人
Feng_Sir
func main() {
bools := make(chan bool, 3)
chanstrings := make(chan string, 1)
for i := 0; i < 100; i++ {
bools <- true
go func(i int) {
time.Sleep(2 * time.Second)
log.Println(time.Now(), i)
<-bools
}(i)
if i == 99 {
chanstrings <- ""
}
}
<-chanstrings
}