Pass GCS object params directly to goroutine

This commit is contained in:
Tom Berger 2018-07-25 12:51:07 -04:00
parent a1273df6cd
commit 82e140d317
1 changed files with 6 additions and 6 deletions

View File

@ -119,9 +119,7 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
ID: i, ID: i,
} }
ctx, cancel := context.WithCancel(context.Background()) ctx := context.Background()
defer cancel()
r, err := store.Service.ReadObject(ctx, params) r, err := store.Service.ReadObject(ctx, params)
if err != nil { if err != nil {
if err == storage.ErrObjectNotExist { if err == storage.ErrObjectNotExist {
@ -157,6 +155,8 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
sem := make(chan struct{}, CONCURRENT_SIZE_REQUESTS) sem := make(chan struct{}, CONCURRENT_SIZE_REQUESTS)
errChan := make(chan error) errChan := make(chan error)
ctxCancel, cancel := context.WithCancel(ctx)
defer cancel()
go func() { go func() {
for err := range errChan { for err := range errChan {
@ -175,13 +175,13 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
ID: name, ID: name,
} }
go func() { go func(params GCSObjectParams) {
defer func() { defer func() {
<-sem <-sem
wg.Done() wg.Done()
}() }()
size, err := store.Service.GetObjectSize(ctx, params) size, err := store.Service.GetObjectSize(ctxCancel, params)
if err != nil { if err != nil {
errChan <- err errChan <- err
@ -189,7 +189,7 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
} }
atomic.AddInt64(&offset, size) atomic.AddInt64(&offset, size)
}() }(params)
} }
wg.Wait() wg.Wait()