Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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