【发布时间】:2017-09-03 03:31:28
【问题描述】:
我有一个函数a:
func a(input *some_type) {
// do sth.
b(input)
}
这个函数被多次调用。
我想要一个函数 b 无限期地等待来自函数 a 的输入,并在它收集到 n 个输入时执行一个操作。
func b(input *some_type) {
// wait until received n inputs then do sth. with all inputs
}
我该怎么做呢?我的第一个想法是使用sync.WaitGroup 和a 和b 之间的频道。
【问题讨论】:
标签: asynchronous go synchronization channel