How to use errgroup to handle multiple asynchronous processes at the end
func main() {
eg := errgroup.Group{}
for i := 0; i < 5; i++ {
i := i //← This is the point
eg.Go(func() error {
fmt.Printf("i:%d\n", i)
return nil
})
}
if err := eg.Wait(); err != nil {
fmt.Printf("err:%v\n", err)
}
}
https://play.golang.org/p/MCkoaPl14ZY
Recommended Posts