Created
July 9, 2015 19:33
-
-
Save sethetter/c9898b5a5413e06e0a9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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