LoginSignup
0
0

More than 3 years have passed since last update.

現場で使えるゴルーチン(並列制御)

Posted at
func main() {
    ch := make(chan struct{}, 10)
    var wg sync.WaitGroup
    for i := 0; i < 1000; i++ {
        ch <- struct{}{}
        wg.Add(1)
        go func(i int) {
            defer func() {
                <-ch
                wg.Done()
            }()

            fmt.Println(i)
        }(i)
    }
    wg.Wait()
}

0
0
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
0