多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
所有任务完成 === ~~~ 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()) } ~~~