Skip to content

Instantly share code, notes, and snippets.

@sethetter
Created July 9, 2015 19:33
Show Gist options
  • Save sethetter/c9898b5a5413e06e0a9d to your computer and use it in GitHub Desktop.
Save sethetter/c9898b5a5413e06e0a9d to your computer and use it in GitHub Desktop.
var myFuncWithPromise = function() {
return new Promise(function(resolve, reject) {
// if everything goes well then..
if (everythingWentWell) return resolve('success!');
// otherwise, reject it and send along an error
return reject(new Error('wtf dude'));
});
};
myFuncWithPromise()
.then(function(result) {
console.log(result); // <-- would be 'success!'
}).catch(function(err) {
console.log(err.message); // <-- would be 'wtf dude'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment