Skip to content

Instantly share code, notes, and snippets.

@mactkg
Created August 31, 2015 03:21
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 mactkg/ca0592ded0d3e145da43 to your computer and use it in GitHub Desktop.
Save mactkg/ca0592ded0d3e145da43 to your computer and use it in GitHub Desktop.
function test() {
return new Promise(function(resolve, reject) {
var r = Math.random();
r > 0.5 ? resolve(r) : reject(r);
});
}
function throwError() {
return new Promise(function(resolve, reject) {
throw new Error("Boom!");
});
}
for(var i = 0; i < 20; i++) {
test().then(function(v) {
console.log("resolved", v);
}).catch(function(v) {
console.log("rejected", v);
});
}
throwError().then(function(v) {
console.log("resoleved", v);
}).catch(function(v) {
console.log("rejected", v);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment