0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

現場で使えるゴルーチン(errgroup.Group編)

Posted at

errgroupを使って複数の非同期処理を最後にまとめてエラーハンドリングする方法

func main() {
	eg := errgroup.Group{}
	for i := 0; i < 5; i++ {
		i := i // ← ここがポイント
		eg.Go(func() error {
			fmt.Printf("i:%d\n", i)
			return nil
		})
	}
	if err := eg.Wait(); err != nil {
		fmt.Printf("err:%v\n", err)
	}
}

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?