diff --git a/lib/util/abortable_operation.js b/lib/util/abortable_operation.js index a59c3c4be4..37fe63d0b0 100644 --- a/lib/util/abortable_operation.js +++ b/lib/util/abortable_operation.js @@ -39,8 +39,8 @@ shaka.util.AbortableOperation = class { /** @private {function():!Promise} */ this.onAbort_ = onAbort; - /** @private {boolean} */ - this.aborted_ = false; + /** @private {?Promise} */ + this.abortPromise_ = null; } /** @@ -48,7 +48,7 @@ shaka.util.AbortableOperation = class { * @export */ get aborted() { - return this.aborted_; + return this.abortPromise_ !== null; } /** @@ -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_; } /** @@ -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.