Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit beb6bb1

Browse files
authored
Merge pull request #1153 from tamird/remove-ununused-cancel
gps: remove unused context.WithCancel
2 parents 28fb6b0 + 02eed27 commit beb6bb1

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

internal/gps/deduce.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ func newDeductionCoordinator(superv *supervisor) *deductionCoordinator {
575575
// the root path and a list of maybeSources, which can be subsequently used to
576576
// create a handler that will manage the particular source.
577577
func (dc *deductionCoordinator) deduceRootPath(ctx context.Context, path string) (pathDeduction, error) {
578-
if dc.suprvsr.getLifetimeContext().Err() != nil {
579-
return pathDeduction{}, errors.New("deductionCoordinator has been terminated")
578+
if err := dc.suprvsr.ctx.Err(); err != nil {
579+
return pathDeduction{}, err
580580
}
581581

582582
// First, check the rootxt to see if there's a prefix match - if so, we

internal/gps/source.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func newSourceCoordinator(superv *supervisor, deducer deducer, cachedir string,
6868
func (sc *sourceCoordinator) close() {}
6969

7070
func (sc *sourceCoordinator) getSourceGatewayFor(ctx context.Context, id ProjectIdentifier) (*sourceGateway, error) {
71-
if sc.supervisor.getLifetimeContext().Err() != nil {
72-
return nil, errors.New("sourceCoordinator has been terminated")
71+
if err := sc.supervisor.ctx.Err(); err != nil {
72+
return nil, err
7373
}
7474

7575
normalizedName := id.normalizedSource()

internal/gps/source_manager.go

+10-17
Original file line numberDiff line numberDiff line change
@@ -593,21 +593,18 @@ type durCount struct {
593593
}
594594

595595
type supervisor struct {
596-
ctx context.Context
597-
cancelFunc context.CancelFunc
598-
mu sync.Mutex // Guards all maps
599-
cond sync.Cond // Wraps mu so callers can wait until all calls end
600-
running map[callInfo]timeCount
601-
ran map[callType]durCount
596+
ctx context.Context
597+
mu sync.Mutex // Guards all maps
598+
cond sync.Cond // Wraps mu so callers can wait until all calls end
599+
running map[callInfo]timeCount
600+
ran map[callType]durCount
602601
}
603602

604603
func newSupervisor(ctx context.Context) *supervisor {
605-
ctx, cf := context.WithCancel(ctx)
606604
supv := &supervisor{
607-
ctx: ctx,
608-
cancelFunc: cf,
609-
running: make(map[callInfo]timeCount),
610-
ran: make(map[callType]durCount),
605+
ctx: ctx,
606+
running: make(map[callInfo]timeCount),
607+
ran: make(map[callType]durCount),
611608
}
612609

613610
supv.cond = sync.Cond{L: &supv.mu}
@@ -635,16 +632,12 @@ func (sup *supervisor) do(inctx context.Context, name string, typ callType, f fu
635632
return err
636633
}
637634

638-
func (sup *supervisor) getLifetimeContext() context.Context {
639-
return sup.ctx
640-
}
641-
642635
func (sup *supervisor) start(ci callInfo) (context.Context, error) {
643636
sup.mu.Lock()
644637
defer sup.mu.Unlock()
645-
if sup.ctx.Err() != nil {
638+
if err := sup.ctx.Err(); err != nil {
646639
// We've already been canceled; error out.
647-
return nil, sup.ctx.Err()
640+
return nil, err
648641
}
649642

650643
if existingInfo, has := sup.running[ci]; has {

0 commit comments

Comments
 (0)