Skip to content

Commit 4562edd

Browse files
committed
fix: use context cancellation for quick stop
1 parent f659d46 commit 4562edd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pkg/goanalysis/runner_action.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package goanalysis
22

33
import (
4+
"context"
45
"fmt"
56
"runtime/debug"
67

@@ -28,11 +29,12 @@ func (actAlloc *actionAllocator) alloc() *action {
2829
return act
2930
}
3031

31-
func (act *action) waitUntilDependingAnalyzersWorked(stopChan chan struct{}) {
32+
func (act *action) waitUntilDependingAnalyzersWorked(ctx context.Context, stopChan chan struct{}) {
3233
for _, dep := range act.Deps {
3334
if dep.Package == act.Package {
3435
select {
3536
case <-stopChan:
37+
case <-ctx.Done():
3638
return
3739
case <-dep.analysisDoneCh:
3840
}

pkg/goanalysis/runner_loadingpackage.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package goanalysis
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"go/ast"
@@ -84,15 +85,17 @@ func (lp *loadingPackage) analyze(stopChan chan struct{}, loadMode LoadMode, loa
8485
return
8586
}
8687

87-
var actsWg errgroup.Group
88+
actsWg, ctx := errgroup.WithContext(context.Background())
8889

8990
for _, act := range lp.actions {
9091
actsWg.Go(func() error {
91-
act.waitUntilDependingAnalyzersWorked(stopChan)
92+
act.waitUntilDependingAnalyzersWorked(ctx, stopChan)
9293

9394
select {
9495
case <-stopChan:
9596
return nil
97+
case <-ctx.Done():
98+
return nil
9699
default:
97100
}
98101

0 commit comments

Comments
 (0)