【发布时间】:2017-08-17 02:27:35
【问题描述】:
我有以下函数可以衍生出一定数量的 go 例程
func (r *Runner) Execute() {
var wg sync.WaitGroup
wg.Add(len(r.pipelines))
for _, p := range r.pipelines {
go executePipeline(p, &wg)
}
wg.Wait()
errs := ....//contains list of errors reported by any/all go routines
}
我在想频道可能有一些方法,但我似乎无法弄清楚。
【问题讨论】:
-
创建一个大小为
len(r.pipelines)的切片,并让每个工作人员写入其对应的索引。 -
有一种模式可以将一些频道的结果合并到一个名为 Fan In 的频道中。您可以在该模式中使用该方法(不一定是模式本身)。