union: add cancel to ctx

This commit is contained in:
Max Sum 2019-12-03 13:37:02 +08:00 committed by Nick Craig-Wood
parent 998169fc02
commit 3cd1b20236
2 changed files with 4 additions and 2 deletions

View File

@ -52,7 +52,8 @@ func (p *Newest) newest(ctx context.Context, upstreams []*upstream.Fs, path stri
func (p *Newest) newestEntries(entries []upstream.Entry) (upstream.Entry, error) { func (p *Newest) newestEntries(entries []upstream.Entry) (upstream.Entry, error) {
var wg sync.WaitGroup var wg sync.WaitGroup
mtimes := make([]time.Time, len(entries)) mtimes := make([]time.Time, len(entries))
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
for i, e := range entries { for i, e := range entries {
wg.Add(1) wg.Add(1)
i, e := i, e // Closure i, e := i, e // Closure

View File

@ -307,7 +307,8 @@ func (f *Fs) updateUsageCore(lock bool) error {
defer f.cacheMutex.Unlock() defer f.cacheMutex.Unlock()
} }
// Run in background, should not be cancelled by user // Run in background, should not be cancelled by user
ctx, _ := context.WithTimeout(context.Background(), 15*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
usage, err := f.Features().About(ctx) usage, err := f.Features().About(ctx)
if err != nil { if err != nil {
return err return err