如何使用go channel同时处理2个进程

how to use go channel to handle 2 process concurrently

下面是2个方法流程。首先按顺序得到method01中的4个batch list,每个batch list的start_id就是上一个batch的last_id。在那之后,我想通过使用 go channel 同时为每个结果批处理 运行 method02,如何编写它的高可用性

for 0 range 3:{
    list := method01(id, limit)
    id := list[len(list) - 1].getId()
}
// for each above batch list, do method02 concurrently
method02(list)
for i:=0; i < 3; i++ {
    list := method01(id, limit)
    id := list[len(list) - 1].getId()
    // for each above batch list, do method02 concurrently
    go method02(list)
}

go 关键字是使函数并发所需的全部内容。您可以在 go tour page. I also would suggest to use something like sync.WaitGroup 了解更多信息,这样您就可以等待流程完成。