本文共 260 字,大约阅读时间需要 1 分钟。
package mainimport ( "fmt" "time")func main() { ch := make(chan struct{}) nums := make([]int, 10) go func() { time.Sleep(time.Second * 5) for i := 0; i < len(nums); i++ { nums[i] = i } ch <- struct{}{} }() <-ch fmt.Println(nums)}/*[0 1 2 3 4 5 6 7 8 9]*/
转载地址:http://leaa.baihongyu.com/