Last active
August 29, 2015 14:21
-
-
Save MattJermyWright/3fdd6057eda2fef22777 to your computer and use it in GitHub Desktop.
HP: Ensighten EDL / Promise architecture in triggers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function trigger() { // Used as a custom trigger for EDLs | |
console.log("PROMISE: Initiating Promise"); | |
var p = Bootstrapper.when.defer(); | |
var waitTime = 10; // Default MS to wait until resolved | |
(function waitForResolution() { | |
console.log("PROMISE: Waiting for value TestDataTrigger to exist: " + waitTime); | |
waitTime = waitTime * 2; // Exponential Backoff - wait longer and longer between calls | |
if(!window.TestDataTrigger) { | |
setTimeout(waitForResolution,waitTime); | |
} else { | |
console.log("PROMISE: Resolved"); | |
p.resolve(); | |
} | |
})(); | |
return p.promise; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Execute async function to pull back data - special thanks to my good friend Deep @ Ensighten | |
function trigger() { | |
var p = Bootstrapper.when.defer(); | |
someExternalProcess.getPageViewData(function(_data) { | |
if (typeof(_data) != "undefined") { | |
if (typeof(_data.siteName) != "undefined" && typeof(_data.pageHierarchy) != "undefined") { | |
window.someGlobalVariable = _data.siteName + ":" + _data.pageHierarchy.join(":"); | |
p.resolve(); | |
} | |
} | |
}); | |
return p.promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment