()
| 313 | } |
| 314 | |
| 315 | update() { |
| 316 | for (let i = 0; i < this.task.length; i++) { |
| 317 | if (!this.task[i]) continue; |
| 318 | if (this.task[i]!.status == "completed") { |
| 319 | this.task[i] = undefined; |
| 320 | } |
| 321 | } |
| 322 | if (this.status == "suspend") { |
| 323 | if (this.files.size == 0) { |
| 324 | this.status = "stopped"; |
| 325 | } |
| 326 | return; |
| 327 | } |
| 328 | let removeFile = false; |
| 329 | for (const task of this.task) { |
| 330 | if (!task) continue; |
| 331 | if (task.status == "removing") { |
| 332 | removeFile = true; |
| 333 | } |
| 334 | if (task.status == "failed") { |
| 335 | task.status = "pending"; |
| 336 | this.suspend(); |
| 337 | } |
| 338 | } |
| 339 | if (this.status == "working" && this.current) { |
| 340 | const currentFile = this.files.get(this.current)!; |
| 341 | let reachTaskEnd = removeFile; |
| 342 | |
| 343 | if (removeFile) { |
| 344 | this.task = []; |
| 345 | } |
| 346 | |
| 347 | for (let i = 0; i < UploadService.concurrency; i++) { |
| 348 | if (reachTaskEnd || !currentFile.prepared) { |
| 349 | break; |
| 350 | } |
| 351 | if (this.task[i] == undefined) { |
| 352 | const nextTask = currentFile.nextTask(); |
| 353 | if (!nextTask) { |
| 354 | reachTaskEnd = true; |
| 355 | break; |
| 356 | } |
| 357 | this.task[i] = nextTask; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | let tasks = 0; |
| 362 | for (const uploadTask of this.task) { |
| 363 | if (!uploadTask) continue; |
| 364 | tasks++; |
| 365 | if (uploadTask.status != "pending") continue; |
| 366 | uploadTask.retries = 0; |
| 367 | uploadTask.start(); // async |
| 368 | } |
| 369 | if (reachTaskEnd && currentFile.prepared && tasks == 0) { |
| 370 | const currentFile = this.files.get(this.current)!; |
| 371 | currentFile.onEnd(); |
| 372 | if (!removeFile) { |
no test coverage detected