@@ -26,10 +26,11 @@ var (
26
26
mainWindow fyne.Window
27
27
downloadButton * widget.Button
28
28
threadContainer * fyne.Container
29
+ usedContainers []* fyne.Container
29
30
activeWorkers int
30
31
downloading bool
31
32
32
- workers int = 16
33
+ workers int = 32
33
34
chunkSize int64 = 512000
34
35
timeout int = 10
35
36
userAgent string = "go-http-client/paralload"
@@ -106,6 +107,16 @@ func main() {
106
107
mainWindow .ShowAndRun ()
107
108
}
108
109
110
+ func cleanContainers () {
111
+ for downloading || activeWorkers >= 1 {
112
+ for _ , container := range usedContainers {
113
+ threadContainer .Remove (container )
114
+ }
115
+ threadContainer .Refresh ()
116
+ time .Sleep (50 * time .Millisecond )
117
+ }
118
+ }
119
+
109
120
func enableDownloads () {
110
121
downloadButton .SetText ("Download" )
111
122
downloadButton .Enable ()
@@ -212,6 +223,7 @@ func startDownload(url string, path string, contentLength int64, outputFile *os.
212
223
213
224
var workerId int
214
225
var offset int64
226
+ go cleanContainers ()
215
227
for offset = 0 ; offset <= contentLength ; offset += chunkSize {
216
228
if ! downloading {
217
229
for activeWorkers > 0 {
@@ -231,11 +243,9 @@ func startDownload(url string, path string, contentLength int64, outputFile *os.
231
243
fyne .NewContainerWithLayout (layout .NewFormLayout (), widget .NewLabel (label ), progressBar ),
232
244
}
233
245
threadContainer .Add (progressBarContainer .container )
234
- threadContainer .Refresh ()
235
246
go downloadChunk (url , path , workerId , outputFile , offset , progressBarContainer )
236
247
activeWorkers ++
237
248
workerId ++
238
- time .Sleep (50 * time .Millisecond )
239
249
}
240
250
for activeWorkers > 0 {
241
251
time .Sleep (1 * time .Second )
@@ -298,7 +308,7 @@ func downloadChunk(url string, path string, workerId int, outputFile *os.File, o
298
308
success = true
299
309
}
300
310
301
- threadContainer . Remove ( progressBarContainer .container )
311
+ usedContainers = append ( usedContainers , progressBarContainer .container )
302
312
activeWorkers --
303
313
}
304
314
0 commit comments