Skip to content

Commit

Permalink
errgroup: drop support for Go versions before 1.20
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Mar 4, 2025
1 parent 960bf1f commit b637f27
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 82 deletions.
2 changes: 1 addition & 1 deletion errgroup/errgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (g *Group) done() {
// 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
}

Expand Down
39 changes: 39 additions & 0 deletions errgroup/errgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,45 @@ func TestGoLimit(t *testing.T) {
}
}

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{}
Expand Down
13 changes: 0 additions & 13 deletions errgroup/go120.go

This file was deleted.

54 changes: 0 additions & 54 deletions errgroup/go120_test.go

This file was deleted.

14 changes: 0 additions & 14 deletions errgroup/pre_go120.go

This file was deleted.

0 comments on commit b637f27

Please sign in to comment.