本文共 276 字,大约阅读时间需要 1 分钟。
借助一个切片来完成
s := make([]chan int, 0)for i := 0; i < 10; i++ { t := make(chan int) s = append(s, t) n := i go func() { t <- n }()}rand.Seed(time.Now().UnixNano())for _, v := range s { k := 1+rand.Int63n(6) time.Sleep(time.Duration(k) * time.Second) fmt.Println(<-v)}
转载地址:http://ujaui.baihongyu.com/