Files
shaka-player/lib/util/operation_manager.js
T
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07:00

52 lines
1.3 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.util.OperationManager');
goog.require('shaka.util.ArrayUtils');
goog.require('shaka.util.IDestroyable');
/**
* A utility for cleaning up AbortableOperations, to help simplify common
* patterns and reduce code duplication.
*
* @implements {shaka.util.IDestroyable}
*/
shaka.util.OperationManager = class {
constructor() {
/** @private {!Array.<!shaka.extern.IAbortableOperation>} */
this.operations_ = [];
}
/**
* Manage an operation. This means aborting it on destroy() and removing it
* from the management set when it complete.
*
* @param {!shaka.extern.IAbortableOperation} operation
*/
manage(operation) {
this.operations_.push(operation.finally(() => {
shaka.util.ArrayUtils.remove(this.operations_, operation);
}));
}
/** @override */
destroy() {
const cleanup = [];
for (const op of this.operations_) {
// Catch and ignore any failures. This silences error logs in the
// JavaScript console about uncaught Promise failures.
op.promise.catch(() => {});
// Now abort the operation.
cleanup.push(op.abort());
}
this.operations_ = [];
return Promise.all(cleanup);
}
};