Skip to content

Commit

Permalink
fix(downloader): download abort log. close iyear#1
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Sep 6, 2022
1 parent 237952c commit 37aa442
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package downloader

import (
"context"
"errors"
"fmt"
"github.com/fatih/color"
"github.com/gabriel-vasile/mimetype"
Expand Down Expand Up @@ -51,7 +52,7 @@ func (d *Downloader) Download(ctx context.Context, limit int) error {
for d.iter.Next(ctx) {
item, err := d.iter.Value(ctx)
if err != nil {
d.pw.Log(color.RedString("[ERROR] Get item failed: %v", err))
d.pw.Log(color.RedString("Get item failed: %v, skip...", err))
continue
}

Expand All @@ -63,15 +64,22 @@ func (d *Downloader) Download(ctx context.Context, limit int) error {

err := wg.Wait()
if err != nil {
if errors.Is(err, context.Canceled) {
d.pw.Log(color.RedString("Download aborted."))
}

d.pw.Stop()
for d.pw.IsRenderInProgress() {
time.Sleep(time.Millisecond * 10)
}
return err
}

for d.pw.IsRenderInProgress() {
if d.pw.LengthActive() == 0 {
d.pw.Stop()
}
time.Sleep(100 * time.Millisecond)
time.Sleep(10 * time.Millisecond)
}

return nil
Expand Down

0 comments on commit 37aa442

Please sign in to comment.