Skip to content

Commit

Permalink
Use errgroup consistently in MultiWrite (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh committed Mar 15, 2021
1 parent bea57ad commit 29b86b5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/v1/remote/multi_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func MultiWrite(m map[name.Reference]Taggable, options ...Option) error {

// Upload individual blobs and collect any errors.
blobChan := make(chan v1.Layer, 2*o.jobs)
var g errgroup.Group
g, ctx := errgroup.WithContext(o.context)
for i := 0; i < o.jobs; i++ {
// Start N workers consuming blobs to upload.
g.Go(func() error {
Expand All @@ -105,12 +105,17 @@ func MultiWrite(m map[name.Reference]Taggable, options ...Option) error {
return nil
})
}
go func() {
g.Go(func() error {
defer close(blobChan)
for _, b := range blobs {
blobChan <- b
select {
case blobChan <- b:
case <-ctx.Done():
return ctx.Err()
}
}
close(blobChan)
}()
return nil
})
if err := g.Wait(); err != nil {
return err
}
Expand Down

0 comments on commit 29b86b5

Please sign in to comment.