Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Use googletag.cmd.push instead of timeout to process queue #16

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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