Create a gist now

Instantly share code, notes, and snippets.

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