image
原文地址:来,控制一下Goroutine的并发数量
问题
funcmain(){
userCount:=math.MaxInt64
fori:=0;i<userCount;i++{
gofunc(iint){
//做一些各种各样的业务逻辑处理
fmt.Printf("gofunc:%dn",i)
time.Sleep(time.Second)
}(i)
}
}
在这里,假设userCount是一个外部传入的参数(不可预测,有可能值非常大),有人会全部丢进去循环。想着全部都并发goro