Created
August 31, 2015 03:21
-
-
Save mactkg/ca0592ded0d3e145da43 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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