Skip to content

Commit cf5c1b6

Browse files
committed
perf(Ads): Reduce VMAP processing time
1 parent b87bf9d commit cf5c1b6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/ads/interstitial_ad_manager.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,13 +699,13 @@ shaka.ads.InterstitialAdManager = class {
699699
shaka.util.Error.Category.ADS,
700700
shaka.util.Error.Code.VAST_INVALID_XML);
701701
}
702+
/** @type {!Array<shaka.extern.AdInterstitial>} */
702703
let interstitials = [];
703704
if (data.tagName == 'VAST') {
704705
interstitials = shaka.ads.Utils.parseVastToInterstitials(
705706
data, this.lastTime_);
706707
} else if (data.tagName == 'vmap:VMAP') {
707-
for (const ad of shaka.ads.Utils.parseVMAP(data)) {
708-
// eslint-disable-next-line no-await-in-loop
708+
const vastProcessing = async (ad) => {
709709
const vastResponseData = await this.makeAdRequest_(ad.uri, context);
710710
const vast = shaka.util.TXml.parseXml(vastResponseData, 'VAST');
711711
if (!vast) {
@@ -716,6 +716,13 @@ shaka.ads.InterstitialAdManager = class {
716716
}
717717
interstitials.push(...shaka.ads.Utils.parseVastToInterstitials(
718718
vast, ad.time));
719+
};
720+
const promises = [];
721+
for (const ad of shaka.ads.Utils.parseVMAP(data)) {
722+
promises.push(vastProcessing(ad));
723+
}
724+
if (promises.length) {
725+
await Promise.all(promises);
719726
}
720727
}
721728
this.addInterstitials(interstitials);

0 commit comments

Comments
 (0)