Skip to content

Instantly share code, notes, and snippets.

@viswesh
Last active March 4, 2018 03:51
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 viswesh/f7ffb1ecab22db8f1b978f601dc77f01 to your computer and use it in GitHub Desktop.
Save viswesh/f7ffb1ecab22db8f1b978f601dc77f01 to your computer and use it in GitHub Desktop.
JavaScript promise sample
let promise = new Promise((resolve, reject) => {
//invoke async operation, then
if (/* success */) {
resolve("response received! Success!");
} else {
reject(Error("Something failed"));
}
});
promise.then(function(result) {
console.log(result); // "response received! Success!"
}, function(err) {
console.log(err); // Error: "Something failed"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment