Skip to content

Commit 419cecf

Browse files
committed
new fix
the steps: 1 upload one file A then start upload 2 add new file(s) B 2.1 if A is Uploading and A's uploading chunks's length less than simultaneousUploads then should upload next chunk
1 parent 3d6db4d commit 419cecf

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

src/flow.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,29 @@
442442
});
443443
return uploading;
444444
},
445-
446-
uploadingNum: function () {
445+
446+
/**
447+
* should upload next chunk
448+
* @function
449+
* @returns {boolean|number}
450+
*/
451+
_shouldUploadNext: function () {
447452
var num = 0;
453+
var should = true;
454+
var simultaneousUploads = this.opts.simultaneousUploads;
448455
each(this.files, function (file) {
449-
if (file.isUploading()) {
450-
num++;
451-
}
456+
each(file.chunks, function(chunk) {
457+
if (chunk.status() === 'uploading') {
458+
num++;
459+
if (num >= simultaneousUploads) {
460+
should = false;
461+
return false;
462+
}
463+
}
464+
});
452465
});
453-
return num;
466+
// if should is true then return uploading chunks's length
467+
return should && num;
454468
},
455469

456470
/**
@@ -459,14 +473,14 @@
459473
*/
460474
upload: function () {
461475
// Make sure we don't start too many uploads at once
462-
var uploadingNum = this.uploadingNum();
463-
if (uploadingNum >= this.opts.simultaneousUploads) {
476+
var ret = this._shouldUploadNext();
477+
if (ret === false) {
464478
return;
465479
}
466480
// Kick off the queue
467481
this.fire('uploadStart');
468482
var started = false;
469-
for (var num = 1; num <= this.opts.simultaneousUploads - uploadingNum; num++) {
483+
for (var num = 1; num <= this.opts.simultaneousUploads - ret; num++) {
470484
started = this.uploadNextChunk(true) || started;
471485
}
472486
if (!started) {

0 commit comments

Comments
 (0)