Original post

Hi,

Is there a way to pass an argument to errgroup routines just like we do in classic go routines?

Thanks

classic way

for i := 1; i < 5; i++ {
  id := i
  go func(id int) {
    if id == 3 {
      return error ....
    }
    // carry on running
  }(id)
}

errgroup way

var eg errgroup.Group

for i := 1; i < 5; i++ {
  id := i
  eg.Go(func() error {
    if id == 3 { // How do I get the id here?
      return error ....
    }
    // carry on running
  })
}