Skip to content

Instantly share code, notes, and snippets.

@taktran
Created September 3, 2014 16:00
Show Gist options
  • Save taktran/0755004ac3a6dad458cb to your computer and use it in GitHub Desktop.
Save taktran/0755004ac3a6dad458cb to your computer and use it in GitHub Desktop.
AngularJS resolve with a timeout
{
resolve: {
/**
* Resolve salesforce connection before loading search
*/
salesforceConnect: function(
$q,
CONFIG,
salesforceService
) {
var deferred = $q.defer();
// Continue if already connected
if (salesforceService.isConnected()) {
deferred.resolve();
return deferred.promise;
}
// Timeout in case you can't connect
var tId = setTimeout(function() {
console.log("Timed out from salesforce connection");
deferred.resolve();
}, CONFIG.sfTimeout);
// First connection
salesforceService.connect().then(function() {
clearTimeout(tId);
deferred.resolve();
}, function() {
clearTimeout(tId);
deferred.reject();
});
return deferred.promise;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment