Skip to content

Commit

Permalink
Refactor to embed gocontext.Context into aptly context
Browse files Browse the repository at this point in the history
  • Loading branch information
smira committed Nov 30, 2017
1 parent 15618c8 commit b7490fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
8 changes: 4 additions & 4 deletions cmd/mirror_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
for idx := range queue {
select {
case downloadQueue <- idx:
case <-context.GoContext().Done():
case <-context.Done():
return
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {

// download file...
e = context.Downloader().DownloadWithChecksum(
context.GoContext(),
context,
repo.PackageURL(task.File.DownloadURL()).String(),
task.TempDownPath,
&task.File.Checksums,
Expand All @@ -181,7 +181,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
}

task.Done = true
case <-context.GoContext().Done():
case <-context.Done():
return
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
context.Progress().ShutdownBar()

select {
case <-context.GoContext().Done():
case <-context.Done():
return fmt.Errorf("unable to update: interrupted")
default:
}
Expand Down
14 changes: 3 additions & 11 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
type AptlyContext struct {
sync.Mutex

ctx gocontext.Context
gocontext.Context

flags, globalFlags *flag.FlagSet
configLoaded bool
Expand Down Expand Up @@ -442,14 +442,6 @@ func (context *AptlyContext) GlobalFlags() *flag.FlagSet {
return context.globalFlags
}

// GoContext returns instance of Go context.Context for the current session
func (context *AptlyContext) GoContext() gocontext.Context {
context.Lock()
defer context.Unlock()

return context.ctx
}

// GoContextHandleSignals upgrades context to handle ^C by aborting context
func (context *AptlyContext) GoContextHandleSignals() {
context.Lock()
Expand All @@ -461,7 +453,7 @@ func (context *AptlyContext) GoContextHandleSignals() {

var cancel gocontext.CancelFunc

context.ctx, cancel = gocontext.WithCancel(context.ctx)
context.Context, cancel = gocontext.WithCancel(context.Context)

go func() {
<-sigch
Expand Down Expand Up @@ -527,7 +519,7 @@ func NewContext(flags *flag.FlagSet) (*AptlyContext, error) {
flags: flags,
globalFlags: flags,
dependencyOptions: -1,
ctx: gocontext.TODO(),
Context: gocontext.TODO(),
publishedStorages: map[string]aptly.PublishedStorage{},
}

Expand Down

0 comments on commit b7490fe

Please sign in to comment.