Skip to content

Instantly share code, notes, and snippets.

@conanak99
Created March 8, 2016 23:46
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 conanak99/d1f70f6a495d6d473817 to your computer and use it in GitHub Desktop.
Save conanak99/d1f70f6a495d6d473817 to your computer and use it in GitHub Desktop.
// 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