Skip to content

Instantly share code, notes, and snippets.

@adambankin
Last active March 15, 2017 20:47
Show Gist options
  • Save adambankin/e36f670bb3534e1bda65fe5e153db157 to your computer and use it in GitHub Desktop.
Save adambankin/e36f670bb3534e1bda65fe5e153db157 to your computer and use it in GitHub Desktop.
var initializationPromise = utilsAsync.makePromise(function (resolve, reject) {
checkPendo();
function checkPendo () {
var delay = 0;
if (window.pendo === undefined) {
if (delay < 8) {
setTimeout(checkPendo, (delay = Math.max(delay *= 2, 1)) * 1000);
} else {
// TODO: handle failure(?)
console.warn('pendo did not load');
reject(new Error("pendo did not load"));
}
} else {
resolve(window.pendo);
}
}
});
// or
var initializationPromise = utilsAsync.makePromise(function (resolve, reject) {
var counter = 0;
function checkPendo () {
if (window.pendo === undefined) {
if (counter < 8) {
counter++;
setTimeout(checkPendo, 1000);
}
} else {
resolve(window.pendo);
}
}
checkPendo();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment