fix(ctx): consider ctx done

This commit is contained in:
iyear 2022-09-16 00:05:25 +08:00
parent 7139f4200f
commit 216ad34f61
2 changed files with 12 additions and 0 deletions

View file

@ -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)

View file

@ -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).