企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
所有任务完成 === ~~~ 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()) } ~~~