Skip to content

Commit

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

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

/**
Expand Down Expand Up @@ -110,8 +110,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 @@ -166,7 +168,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 adc646a

Please sign in to comment.