Skip to content

Instantly share code, notes, and snippets.

@Andygmb
Created August 27, 2015 14:00
Show Gist options
  • Save Andygmb/6cb27ba326695efe7ffc to your computer and use it in GitHub Desktop.
Save Andygmb/6cb27ba326695efe7ffc to your computer and use it in GitHub Desktop.
function retry(retries, assertion, timeout, callbackSuccess, callbackFailure){
var i = 0;
function _retry() {
i++;
if (assertion) {
callbackSuccess();
} else {
if (i < retries) {
setTimeout(_retry, timeout);
} else if (callbackFailure != undefined & i > retries) {
callbackFailure();
}
}
}
_retry()
}
var assertion = function(){FB.length > 0}
var callbackFailure = function(){displayError(".fb-messages-box", "An error occurred", "Could not set up Facebook SDK.");}
retry(4, assertion, 500, get_fb_pages, callbackFailure)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment