Created
April 12, 2017 23:13
-
-
Save asimmittal/946d9e5d48bcb93bf7869991074ef7d8 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 promise = new Promise(function(resolve,reject){ | |
/* | |
* Do things here (synchronous or asynchronous) | |
* some examples: | |
* -- run loops | |
* -- perform ajax requests | |
* -- count sheep! | |
*/ | |
if(some_desired_condition) | |
resolve(some_desired_arg) | |
else | |
reject(some_other_arg) | |
}); | |
promise.then(function(some_desired_arg){ | |
/* | |
* handle desired output | |
* other examples online might call this "Success" | |
*/ | |
}).catch(function(some_other_arg){ | |
/* | |
* handle other output | |
* other examples online might call this "Fail" | |
*/ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment