Skip to content

Commit

Permalink
fix(lib): go routine to assure instance context cancellation now clos…
Browse files Browse the repository at this point in the history
…es properly
  • Loading branch information
ramfox committed Nov 8, 2021
1 parent 8e42673 commit 5d378d3
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,6 @@ func OptDscache(dscache *dscache.Dscache) Option {
// function must check whether their fields are nil or not.
func NewInstance(ctx context.Context, repoPath string, opts ...Option) (qri *Instance, err error) {
log.Debugw("NewInstance", "repoPath", repoPath, "opts", opts)
go func() {
for {
select {
case <-ctx.Done():
log.Debug("Instance context canceled")
}
}
}()

ctx, cancel := context.WithCancel(ctx)
ok := false
defer func() {
Expand All @@ -374,6 +365,14 @@ func NewInstance(ctx context.Context, repoPath string, opts ...Option) (qri *Ins
}
}()

go func() {
select {
case <-ctx.Done():
log.Debug("Instance context canceled")
return
}
}()

if repoPath == "" {
return nil, fmt.Errorf("repo path is required")
}
Expand Down

0 comments on commit 5d378d3

Please sign in to comment.