Improve cancellation

This commit is contained in:
Xpl0itU 2024-04-03 19:41:46 +02:00
parent 624c96b7e8
commit f927c43c1b
3 changed files with 15 additions and 9 deletions

View file

@ -50,7 +50,7 @@ func downloadFile(ctx context.Context, progressReporter ProgressReporter, client
updateProgress := func(downloaded *int64) {
for range ticker.C {
if progressReporter.Cancelled() {
break
return
}
progressReporter.UpdateDownloadProgress(*downloaded, calculateDownloadSpeed(*downloaded, startTime, time.Now()), filePath)
}
@ -100,7 +100,7 @@ func downloadFile(ctx context.Context, progressReporter ProgressReporter, client
go updateProgress(&downloaded)
customBufferedWriter, err := NewFileWriterWithProgress(file, &downloaded)
customBufferedWriter, err := NewFileWriterWithProgress(file, &downloaded, progressReporter)
if err != nil {
resp.CloseBodyStream()
file.Close()