Skip to content

Commit

Permalink
chore: Use promiseWithTimeout where possible (#7716)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Dec 5, 2024
1 parent 1d44f70 commit 554c326
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
14 changes: 3 additions & 11 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2012,18 +2012,10 @@ shaka.media.DrmEngine = class {
* @private
*/
async closeSession_(session) {
const DrmEngine = shaka.media.DrmEngine;

const timeout = new Promise((resolve, reject) => {
const timer = new shaka.util.Timer(reject);
timer.tickAfter(DrmEngine.CLOSE_TIMEOUT_);
});

try {
await Promise.race([
Promise.all([session.close(), session.closed]),
timeout,
]);
await shaka.util.Functional.promiseWithTimeout(
shaka.media.DrmEngine.CLOSE_TIMEOUT_,
Promise.all([session.close(), session.closed]));
} catch (e) {
shaka.log.warning('Timeout waiting for session close');
}
Expand Down
11 changes: 2 additions & 9 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3142,15 +3142,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
fullyLoaded.reject(this.videoErrorToShakaError_());
});

const timeout = new Promise((resolve, reject) => {
const timer = new shaka.util.Timer(reject);
timer.tickAfter(this.config_.streaming.loadTimeout);
});

await Promise.race([
fullyLoaded,
timeout,
]);
await shaka.util.Functional.promiseWithTimeout(
this.config_.streaming.loadTimeout, fullyLoaded);

const isLive = this.isLive();

Expand Down

0 comments on commit 554c326

Please sign in to comment.