Skip to content

Instantly share code, notes, and snippets.

@jwasinger
Last active August 29, 2015 14:24
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 jwasinger/c26faa9cdc82f8bd051f to your computer and use it in GitHub Desktop.
Save jwasinger/c26faa9cdc82f8bd051f to your computer and use it in GitHub Desktop.
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