Skip to content

Instantly share code, notes, and snippets.

@riston
Created May 21, 2015 14:32
Show Gist options
  • Save riston/2b91e464d03700c399e2 to your computer and use it in GitHub Desktop.
Save riston/2b91e464d03700c399e2 to your computer and use it in GitHub Desktop.
Promise example
var p1 = new Promise(function (resolve) {
return resolve(10);
});
var add = function (num) {
return new Promise(function (resolve) {
return resolve(10 + num);
});
};
p1
.then(function (result) {
console.log("First result", result);
return result;
})
.then(function (prevResult) {
console.log("Prev", prevResult);
return add(prevResult);
})
.then(function (final) {
console.log("Final result", final);
// Awesome throw error
throw Error("I Am awesome");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment