Skip to content

Commit b3d3e34

Browse files
committed
fix: throw single complete event
1 parent 5b13bde commit b3d3e34

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/resumable.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
* @returns {boolean}
237237
* @private
238238
*/
239-
uploadNextChunk: function () {
239+
uploadNextChunk: function (preventEvents) {
240240
// In some cases (such as videos) it's really handy to upload the first
241241
// and last chunk of a file quickly; this let's the server check the file's
242242
// metadata and determine if there's even a point in continuing.
@@ -290,7 +290,7 @@
290290
return false;
291291
}
292292
});
293-
if (!outstanding) {
293+
if (!outstanding && !preventEvents) {
294294
// All chunks have been uploaded, complete
295295
this.fire('complete');
296296
}
@@ -421,8 +421,12 @@
421421
}
422422
// Kick off the queue
423423
this.fire('uploadStart');
424+
var started = false;
424425
for (var num = 1; num <= this.opts.simultaneousUploads; num++) {
425-
this.uploadNextChunk();
426+
started = this.uploadNextChunk(true) || started;
427+
}
428+
if (!started) {
429+
this.fire('complete');
426430
}
427431
},
428432

test/uploadSpec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ describe('upload file', function() {
125125
expect(events[10]).toBe('fileSuccess');
126126
// Can be sync and async
127127
expect(events[11]).toBe('complete');
128+
129+
resumable.upload();
130+
expect(events.length).toBe(14);
131+
expect(events[12]).toBe('uploadStart');
132+
expect(events[13]).toBe('complete');
128133
});
129134

130135
it('should pause and resume file', function () {

0 commit comments

Comments
 (0)