Skip to content

Instantly share code, notes, and snippets.

@dapangmao
Last active January 18, 2016 13:32
Show Gist options
  • Save dapangmao/4ac4e163ef9d51a8cf4f to your computer and use it in GitHub Desktop.
Save dapangmao/4ac4e163ef9d51a8cf4f to your computer and use it in GitHub Desktop.
function someAsyncThing(x) {
return new Promise(function(resolve, reject) {
// this will throw, x does not exist
if (x > 10) {
resolve(x);
} else {
reject(x);
}
});
};
someAsyncThing(343)
.then(function(res) {
console.log('everything is great is ', res);
})
.catch(function(error) {
console.log('oh no', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment