Skip to content

Commit

Permalink
prevent send chunks when it is finished (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Luiz Filho <[email protected]>
  • Loading branch information
luizmacfilho and Luiz Filho authored Jan 30, 2021
1 parent 62f6188 commit a5a2173
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/upchunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class UpChunk {
private attemptCount: number;
private offline: boolean;
private paused: boolean;
private success: boolean;
private currentXhr?: XMLHttpRequest;

private reader: FileReader;
Expand All @@ -69,6 +70,7 @@ export class UpChunk {
this.attemptCount = 0;
this.offline = false;
this.paused = false;
this.success = false;

this.reader = new FileReader();
this.eventTarget = new EventTarget();
Expand Down Expand Up @@ -289,7 +291,7 @@ export class UpChunk {
* handle errors & retries and dispatch events
*/
private sendChunks() {
if (this.paused || this.offline) {
if (this.paused || this.offline || this.success) {
return;
}

Expand All @@ -311,6 +313,7 @@ export class UpChunk {
if (this.chunkCount < this.totalChunks) {
this.sendChunks();
} else {
this.success = true;
this.dispatch('success');
}

Expand Down

0 comments on commit a5a2173

Please sign in to comment.