Skip to content

Instantly share code, notes, and snippets.

@asimmittal
Created April 12, 2017 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asimmittal/946d9e5d48bcb93bf7869991074ef7d8 to your computer and use it in GitHub Desktop.
Save asimmittal/946d9e5d48bcb93bf7869991074ef7d8 to your computer and use it in GitHub Desktop.
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