ObjectLister: rely on the context everywhere

Get rid of the `quit` and `quitOnce` members. Instead, use the context
and its `cancel` function.
This commit is contained in:
Michael Haggerty 2021-09-04 10:50:26 +02:00
Родитель f92082256a
Коммит 4593f41df2
1 изменённых файлов: 4 добавлений и 11 удалений

Просмотреть файл

@ -6,7 +6,6 @@ import (
"math"
"net/http"
"strconv"
"sync"
"time"
"golang.org/x/sync/errgroup"
@ -23,19 +22,14 @@ func newObjectLister(c *Config, b *Bucket, prefixes []string, maxKeys int) (*Obj
l := ObjectLister{
ctx: ctx,
cancel: cancel,
b: &bCopy,
c: &cCopy,
prefixCh: make(chan string, len(prefixes)),
resultCh: make(chan []string, 1),
quit: make(chan struct{}),
maxKeys: maxKeys,
}
go func() {
<-l.quit
cancel()
}()
// Enqueue all of the prefixes that we were given. This won't
// block because we have initialized `prefixCh` to be long enough
// to hold all of them. This has the added benefit that there is
@ -66,6 +60,7 @@ func newObjectLister(c *Config, b *Bucket, prefixes []string, maxKeys int) (*Obj
type ObjectLister struct {
ctx context.Context
cancel context.CancelFunc
b *Bucket
c *Config
@ -75,12 +70,10 @@ type ObjectLister struct {
err error
prefixCh chan string
resultCh chan []string
quit chan struct{}
quitOnce sync.Once
}
func (l *ObjectLister) closeQuit() {
l.quitOnce.Do(func() { close(l.quit) })
l.cancel()
}
func (l *ObjectLister) worker(ctx context.Context) {