func job(index int) int { time.Sleep(time.Millisecond*500) return index } func main() { result:=make(chan int) for i:=0;i<5;i++{ go func(index int) { result<-job(index) }(i) } count:=0 for item:=range result{ count++ fmt.Println(item) if count == 5{ close(result) break } } }
本作品採用《CC 協議》,轉載必須註明作者和本文連結