Skip to content

Commit

Permalink
fix(ctx): consider ctx done
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Sep 15, 2022
1 parent 7139f42 commit 216ad34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func (d *Downloader) Download(ctx context.Context, limit int) error {
}

func (d *Downloader) download(ctx context.Context, item *Item) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
}

tracker := prog.AppendTracker(d.pw, formatter, item.Name, item.Size)
filename := fmt.Sprintf("%s%s", utils.FS.GetNameWithoutExt(item.Name), TempExt)
path := filepath.Join(consts.DownloadPath, filename)
Expand Down
6 changes: 6 additions & 0 deletions pkg/uploader/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (u *Uploader) upload(ctx context.Context, item *Item) error {
_ = R.Close()
}(item.R)

select {
case <-ctx.Done():
return ctx.Err()
default:
}

tracker := prog.AppendTracker(u.pw, formatter, item.Name, item.Size)

up := uploader.NewUploader(u.client).
Expand Down

0 comments on commit 216ad34

Please sign in to comment.