Last active
August 29, 2015 14:24
-
-
Save jwasinger/c26faa9cdc82f8bd051f to your computer and use it in GitHub Desktop.
This file contains 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
function foo() | |
{ | |
var promise = new Promise(); | |
my_async(args, function callback() | |
{ | |
//do something | |
... | |
if(error_happens) | |
{ | |
promise.reject(error_value); //calls the 'error' function in promise.then() | |
} | |
else | |
{ | |
promise.resolve(success_value); //calls the 'success' function on promise.then() | |
} | |
}); | |
return promise; | |
} | |
foo().then(function success(success_val) | |
{ | |
... | |
}, | |
function failure(error_val) | |
{ | |
... | |
}); | |
//this part of the code will likely be reached before functions inside 'then' are executed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment