Skip to content

Commit e6dff61

Browse files
committed
Merge pull request #30 from dolymood/master
fix: upload simultaneousUploads bug
2 parents b577078 + 419cecf commit e6dff61

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

src/flow.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,19 +443,44 @@
443443
return uploading;
444444
},
445445

446+
/**
447+
* should upload next chunk
448+
* @function
449+
* @returns {boolean|number}
450+
*/
451+
_shouldUploadNext: function () {
452+
var num = 0;
453+
var should = true;
454+
var simultaneousUploads = this.opts.simultaneousUploads;
455+
each(this.files, function (file) {
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+
});
465+
});
466+
// if should is true then return uploading chunks's length
467+
return should && num;
468+
},
469+
446470
/**
447471
* Start or resume uploading.
448472
* @function
449473
*/
450474
upload: function () {
451475
// Make sure we don't start too many uploads at once
452-
if (this.isUploading()) {
476+
var ret = this._shouldUploadNext();
477+
if (ret === false) {
453478
return;
454479
}
455480
// Kick off the queue
456481
this.fire('uploadStart');
457482
var started = false;
458-
for (var num = 1; num <= this.opts.simultaneousUploads; num++) {
483+
for (var num = 1; num <= this.opts.simultaneousUploads - ret; num++) {
459484
started = this.uploadNextChunk(true) || started;
460485
}
461486
if (!started) {

0 commit comments

Comments
 (0)