NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
所有任务完成 === ~~~ func runTask(i int) string { time.Sleep(10 * time.Millisecond) return fmt.Sprintf("the result is from %d",i) } func AllResponse() string { numOfRunner := 10 ch := make(chan string,numOfRunner) for i:=0;i<numOfRunner;i++{ go func(i int) { task := runTask(i) ch <- task }(i) } allRet := "" //for i:=range ch { // allRet += i + "\n" //} for i:=0;i<numOfRunner;i++{ allRet += <-ch + "\n" } return allRet } func TestAll(t *testing.T) { t.Log("Bef: ",runtime.NumGoroutine()) t.Log(AllResponse()) //time.Sleep(time.Second) t.Log("End: ",runtime.NumGoroutine()) } ~~~