Skip to content

Commit

Permalink
fix: Abort operations only once (#7624)
Browse files Browse the repository at this point in the history
  • Loading branch information
tykus160 authored and joeyparrish committed Nov 19, 2024
1 parent 31a054e commit a52a87d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/util/abortable_operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ shaka.util.AbortableOperation = class {
/** @private {function():!Promise} */
this.onAbort_ = onAbort;

/** @private {boolean} */
this.aborted_ = false;
/** @private {?Promise} */
this.abortPromise_ = null;
}

/**
* @return {boolean} True if the operation has been aborted.
* @export
*/
get aborted() {
return this.aborted_;
return this.abortPromise_ !== null;
}

/**
Expand Down Expand Up @@ -118,8 +118,10 @@ shaka.util.AbortableOperation = class {
* @export
*/
abort() {
this.aborted_ = true;
return this.onAbort_();
if (!this.abortPromise_) {
this.abortPromise_ = this.onAbort_();
}
return this.abortPromise_;
}

/**
Expand Down Expand Up @@ -174,7 +176,7 @@ shaka.util.AbortableOperation = class {

const makeCallback = (isSuccess) => {
return (value) => {
if (this.aborted_ && isSuccess) {
if (this.abortPromise_ && isSuccess) {
// If "this" is not abortable(), or if abort() is called after "this"
// is complete but before the next stage in the chain begins, we
// should stop right away.
Expand Down

0 comments on commit a52a87d

Please sign in to comment.