Skip to content

Instantly share code, notes, and snippets.

@conanak99

conanak99/promise.js Secret

Created Mar 8, 2016
Embed
What would you like to do?
// Code from: http://www.html5rocks.com/en/tutorials/es6/promises/
var promise = new Promise(function(resolve, reject) {
// do a thing, possibly async, then…
if (true) {
resolve("Stuff worked!");
}
else {
reject(Error("It broke"));
}
});
promise.then(function(result) {
console.log(result); // "Stuff worked!"
}, function(err) {
console.log(err); // Error: "It broke"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment