errgroup: modernize the usage of closures in goroutines Change-Id: I8b8a902fede0a77b11af130868dbf26b67c73ebf Reviewed-on: https://go-review.googlesource.com/c/sync/+/836625 Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Mark Freeman <mark@golang.org> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/errgroup/errgroup_test.go b/errgroup/errgroup_test.go index 3b563af..92ac010 100644 --- a/errgroup/errgroup_test.go +++ b/errgroup/errgroup_test.go
@@ -44,7 +44,6 @@ } for _, url := range urls { // Launch a goroutine to fetch the URL. - url := url // https://golang.org/doc/faq#closures_and_goroutines g.Go(func() error { // Fetch the URL. resp, err := http.Get(url) @@ -71,7 +70,6 @@ searches := []Search{Web, Image, Video} results := make([]Result, len(searches)) for i, search := range searches { - i, search := i, search // https://golang.org/doc/faq#closures_and_goroutines g.Go(func() error { result, err := search(ctx, query) if err == nil { @@ -120,7 +118,6 @@ var firstErr error for i, err := range tc.errs { - err := err g.Go(func() error { return err }) if firstErr == nil && err != nil { @@ -153,7 +150,6 @@ g, ctx := errgroup.WithContext(context.Background()) for _, err := range tc.errs { - err := err g.Go(func() error { return err }) } @@ -267,7 +263,6 @@ g, ctx := errgroup.WithContext(context.Background()) for _, err := range tc.errs { - err := err g.TryGo(func() error { return err }) }