Skip to content

Instantly share code, notes, and snippets.

@YashdalfTheGray
Created November 9, 2015 03:38
Show Gist options
  • Save YashdalfTheGray/faa15c50520f17b4aa24 to your computer and use it in GitHub Desktop.
Save YashdalfTheGray/faa15c50520f17b4aa24 to your computer and use it in GitHub Desktop.
Promise API
server.getData(url)
.then(function(result) {
// this code block runs when the
// promise gets fulfilled.
ctrl.myData = result;
})
.catch(function(error) {
// this code block runs when there
// is an error encountered or if the
// promise was rejected.
console.log('Something went wrong');
console.log(error);
})
.finally(function() {
// this code block runs in all cases
// and can be helpful to run clean up
// type tasks.
server.closeConnection();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment