errgroup: drop support for Go versions before 1.20
Change-Id: I7de5dfae21c4ffe31d6c16e3df0fed3e2269cb16
Reviewed-on: https://go-review.googlesource.com/c/sync/+/654421
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/errgroup/errgroup.go b/errgroup/errgroup.go
index b832259..a4ea5d1 100644
--- a/errgroup/errgroup.go
+++ b/errgroup/errgroup.go
@@ -46,7 +46,7 @@
// returns a non-nil error or the first time Wait returns, whichever occurs
// first.
func WithContext(ctx context.Context) (*Group, context.Context) {
- ctx, cancel := withCancelCause(ctx)
+ ctx, cancel := context.WithCancelCause(ctx)
return &Group{cancel: cancel}, ctx
}
diff --git a/errgroup/errgroup_test.go b/errgroup/errgroup_test.go
index 0358842..2a491bf 100644
--- a/errgroup/errgroup_test.go
+++ b/errgroup/errgroup_test.go
@@ -250,6 +250,45 @@
}
}
+func TestCancelCause(t *testing.T) {
+ errDoom := errors.New("group_test: doomed")
+
+ cases := []struct {
+ errs []error
+ want error
+ }{
+ {want: nil},
+ {errs: []error{nil}, want: nil},
+ {errs: []error{errDoom}, want: errDoom},
+ {errs: []error{errDoom, nil}, want: errDoom},
+ }
+
+ for _, tc := range cases {
+ g, ctx := errgroup.WithContext(context.Background())
+
+ for _, err := range tc.errs {
+ err := err
+ g.TryGo(func() error { return err })
+ }
+
+ if err := g.Wait(); err != tc.want {
+ t.Errorf("after %T.TryGo(func() error { return err }) for err in %v\n"+
+ "g.Wait() = %v; want %v",
+ g, tc.errs, err, tc.want)
+ }
+
+ if tc.want == nil {
+ tc.want = context.Canceled
+ }
+
+ if err := context.Cause(ctx); err != tc.want {
+ t.Errorf("after %T.TryGo(func() error { return err }) for err in %v\n"+
+ "context.Cause(ctx) = %v; tc.want %v",
+ g, tc.errs, err, tc.want)
+ }
+ }
+}
+
func BenchmarkGo(b *testing.B) {
fn := func() {}
g := &errgroup.Group{}
diff --git a/errgroup/go120.go b/errgroup/go120.go
deleted file mode 100644
index f93c740..0000000
--- a/errgroup/go120.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2023 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build go1.20
-
-package errgroup
-
-import "context"
-
-func withCancelCause(parent context.Context) (context.Context, func(error)) {
- return context.WithCancelCause(parent)
-}
diff --git a/errgroup/go120_test.go b/errgroup/go120_test.go
deleted file mode 100644
index 068f104..0000000
--- a/errgroup/go120_test.go
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2023 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build go1.20
-
-package errgroup_test
-
-import (
- "context"
- "errors"
- "testing"
-
- "golang.org/x/sync/errgroup"
-)
-
-func TestCancelCause(t *testing.T) {
- errDoom := errors.New("group_test: doomed")
-
- cases := []struct {
- errs []error
- want error
- }{
- {want: nil},
- {errs: []error{nil}, want: nil},
- {errs: []error{errDoom}, want: errDoom},
- {errs: []error{errDoom, nil}, want: errDoom},
- }
-
- for _, tc := range cases {
- g, ctx := errgroup.WithContext(context.Background())
-
- for _, err := range tc.errs {
- err := err
- g.TryGo(func() error { return err })
- }
-
- if err := g.Wait(); err != tc.want {
- t.Errorf("after %T.TryGo(func() error { return err }) for err in %v\n"+
- "g.Wait() = %v; want %v",
- g, tc.errs, err, tc.want)
- }
-
- if tc.want == nil {
- tc.want = context.Canceled
- }
-
- if err := context.Cause(ctx); err != tc.want {
- t.Errorf("after %T.TryGo(func() error { return err }) for err in %v\n"+
- "context.Cause(ctx) = %v; tc.want %v",
- g, tc.errs, err, tc.want)
- }
- }
-}
diff --git a/errgroup/pre_go120.go b/errgroup/pre_go120.go
deleted file mode 100644
index 88ce334..0000000
--- a/errgroup/pre_go120.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2023 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build !go1.20
-
-package errgroup
-
-import "context"
-
-func withCancelCause(parent context.Context) (context.Context, func(error)) {
- ctx, cancel := context.WithCancel(parent)
- return ctx, func(error) { cancel() }
-}