Skip to content

Commit b637f27

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 960bf1f commit b637f27

File tree

5 files changed

+40
-82
lines changed

5 files changed

+40
-82
lines changed

errgroup/errgroup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (g *Group) done() {
4646
// returns a non-nil error or the first time Wait returns, whichever occurs
4747
// first.
4848
func WithContext(ctx context.Context) (*Group, context.Context) {
49-
ctx, cancel := withCancelCause(ctx)
49+
ctx, cancel := context.WithCancelCause(ctx)
5050
return &Group{cancel: cancel}, ctx
5151
}
5252

errgroup/errgroup_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,45 @@ func TestGoLimit(t *testing.T) {
250250
}
251251
}
252252

253+
func TestCancelCause(t *testing.T) {
254+
errDoom := errors.New("group_test: doomed")
255+
256+
cases := []struct {
257+
errs []error
258+
want error
259+
}{
260+
{want: nil},
261+
{errs: []error{nil}, want: nil},
262+
{errs: []error{errDoom}, want: errDoom},
263+
{errs: []error{errDoom, nil}, want: errDoom},
264+
}
265+
266+
for _, tc := range cases {
267+
g, ctx := errgroup.WithContext(context.Background())
268+
269+
for _, err := range tc.errs {
270+
err := err
271+
g.TryGo(func() error { return err })
272+
}
273+
274+
if err := g.Wait(); err != tc.want {
275+
t.Errorf("after %T.TryGo(func() error { return err }) for err in %v\n"+
276+
"g.Wait() = %v; want %v",
277+
g, tc.errs, err, tc.want)
278+
}
279+
280+
if tc.want == nil {
281+
tc.want = context.Canceled
282+
}
283+
284+
if err := context.Cause(ctx); err != tc.want {
285+
t.Errorf("after %T.TryGo(func() error { return err }) for err in %v\n"+
286+
"context.Cause(ctx) = %v; tc.want %v",
287+
g, tc.errs, err, tc.want)
288+
}
289+
}
290+
}
291+
253292
func BenchmarkGo(b *testing.B) {
254293
fn := func() {}
255294
g := &errgroup.Group{}

errgroup/go120.go

-13
This file was deleted.

errgroup/go120_test.go

-54
This file was deleted.

errgroup/pre_go120.go

-14
This file was deleted.

0 commit comments

Comments
 (0)