File tree 1 file changed +17
-6
lines changed
1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,14 @@ func (g *TaskGroup) Wait() {
32
32
// TaskGroupWithContext represents a group of related tasks associated to a context
33
33
type TaskGroupWithContext struct {
34
34
TaskGroup
35
- ctx context.Context
36
- cancel context.CancelFunc
37
- errOnce sync.Once
38
- err error
35
+ ctx context.Context
36
+ cancel context.CancelFunc
37
+
38
+ errSync struct {
39
+ once sync.Once
40
+ guard sync.RWMutex
41
+ }
42
+ err error
39
43
}
40
44
41
45
// Submit adds a task to this group and sends it to the worker pool to be executed
@@ -57,8 +61,11 @@ func (g *TaskGroupWithContext) Submit(task func() error) {
57
61
// don't actually ignore errors
58
62
err := task ()
59
63
if err != nil {
60
- g .errOnce .Do (func () {
64
+ g .errSync .once .Do (func () {
65
+ g .errSync .guard .Lock ()
61
66
g .err = err
67
+ g .errSync .guard .Unlock ()
68
+
62
69
if g .cancel != nil {
63
70
g .cancel ()
64
71
}
@@ -86,5 +93,9 @@ func (g *TaskGroupWithContext) Wait() error {
86
93
case <- g .ctx .Done ():
87
94
}
88
95
89
- return g .err
96
+ g .errSync .guard .RLock ()
97
+ err := g .err
98
+ g .errSync .guard .RUnlock ()
99
+
100
+ return err
90
101
}
You can’t perform that action at this time.
0 commit comments