Last active
March 4, 2018 03:51
-
-
Save viswesh/f7ffb1ecab22db8f1b978f601dc77f01 to your computer and use it in GitHub Desktop.
JavaScript promise sample
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
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