ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
按需任意任务完成 === ~~~ func runTask(i int) string { time.Sleep(10 * time.Millisecond) return fmt.Sprintf("the result is from %d",i) } func FirstResponse() string { numOfRunner := 10 ch := make(chan string,numOfRunner) for i:=0;i<numOfRunner;i++{ go func(i int) { task := runTask(i) ch <- task }(i) } return <-ch } func TestFirst(t *testing.T) { fmt.Println("Go num: ",runtime.NumGoroutine()) FirstResponse() time.Sleep(time.Second) fmt.Println("Go num: ",runtime.NumGoroutine()) } ~~~