Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c9f60b

Browse files
committed
fix: use context cancellation for quick stop
1 parentc18f3ff commit8c9f60b

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
returnact
2930
}
3031

31-
func (act*action)waitUntilDependingAnalyzersWorked(stopChanchanstruct{}) {
32+
func (act*action)waitUntilDependingAnalyzersWorked(ctx context.Context,stopChanchanstruct{}) {
3233
for_,dep:=rangeact.Deps {
3334
ifdep.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-
varactsWgerrgroup.Group
88+
actsWg,ctx:=errgroup.WithContext(context.Background())
8889

8990
for_,act:=rangelp.actions {
9091
actsWg.Go(func()error {
91-
act.waitUntilDependingAnalyzersWorked(stopChan)
92+
act.waitUntilDependingAnalyzersWorked(ctx,stopChan)
9293

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp