g.Go(func() error { result, err := makeDBCall() if err != nil { fmt.Println("Error 1") return err } return nil } g.Go(func() error { result, err := makeAnotherDBCall() if err != nil { fmt.Println("Error 2") return err } return nil } g.Go(func() error { result, err := makeAnotherAnotherDBCall() if err != nil { fmt.Println("Error 3") return err } return nil } err := g.Wait() if err != nil { return } fmt.Println("Done with error Group")
I intentionally make one of the dbCall()
functions to return an error. Out of 10 requests made, maybe 3-5 have an output of:
Starting err group
Error 1
https://stackoverflow.com/questions/65866317/race-condition-with-errgroup January 24, 2021 at 09:28AMDone with error Group
没有评论:
发表评论