From 58cdc2977408e90426a70501807eed9c6813a85d Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Tue, 5 Feb 2019 12:43:46 -0500 Subject: [PATCH] perf: Use googletag.cmd.push instead of timeout to process queue Use googletag.cmd.push instead of timeout to check if pubads is ready. Fixes issue with recurring handler. --- src/createManager.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/createManager.js b/src/createManager.js index 36e0b94..839c975 100644 --- a/src/createManager.js +++ b/src/createManager.js @@ -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; @@ -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]);