Skip to content

Commit

Permalink
perf: Use googletag.cmd.push instead of timeout to process queue (#16)
Browse files Browse the repository at this point in the history
Use googletag.cmd.push instead of timeout to check if pubads is ready. Fixes issue with recurring
handler.
  • Loading branch information
andrewb authored Feb 5, 2019
1 parent 623b2b2 commit 5af9ce7
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/createManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,6 @@ export class AdManager extends EventEmitter {
return;
}

const checkPubadsReady = cb => {
if (this.pubadsReady) {
cb();
} else {
setTimeout(checkPubadsReady, 50, cb);
}
};

const instances = this.getMountedInstances();
let hasPubAdsService = false;
let dummyAdSlot;
Expand Down Expand Up @@ -398,8 +390,8 @@ export class AdManager extends EventEmitter {
// Enable service
this.googletag.enableServices();

// After the service is enabled, check periodically until `pubadsReady` flag returns true before proceeding the rest.
checkPubadsReady(() => {
// Queue commands that should run once the service is ready
this.googletag.cmd.push(() => {
// destroy dummy ad slot if exists.
if (dummyAdSlot) {
this.googletag.destroySlots([dummyAdSlot]);
Expand Down

0 comments on commit 5af9ce7

Please sign in to comment.