diff --git a/downloader.go b/downloader.go index 9e1f653..a53ecbf 100644 --- a/downloader.go +++ b/downloader.go @@ -82,6 +82,7 @@ func downloadFileWithSemaphore(ctx context.Context, progressReporter ProgressRep if err != nil { file.Close() resp.Body.Close() + writerProgress.Close() if doRetries && attempt < maxRetries && !progressReporter.Cancelled() { time.Sleep(retryDelay) continue @@ -90,6 +91,7 @@ func downloadFileWithSemaphore(ctx context.Context, progressReporter ProgressRep } file.Close() resp.Body.Close() + writerProgress.Close() break } diff --git a/writerProgress.go b/writerProgress.go index 051d4dd..a5df0e9 100644 --- a/writerProgress.go +++ b/writerProgress.go @@ -33,3 +33,8 @@ func (r *WriterProgress) Write(p []byte) (n int, err error) { r.downloadToReport += int64(n) return n, err } + +func (r *WriterProgress) Close() error { + r.updateProgressTicker.Stop() + return nil +}