💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
所有任务完成 === ~~~ 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()) } ~~~