Created
January 14, 2017 07:51
-
-
Save butackle/3ebb36f3a74de17121ef9b0adbfde462 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
const testPromise = (num,sec) => { | |
const random = Math.round(Math.random() * 10); //ランダムで0〜9の数値を返す | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log(num + ": random is " + random); | |
if (random === 3) reject("random is three"); | |
resolve("random is " + random) | |
},sec); | |
}) | |
} | |
const p1 = testPromise(1, 3000); | |
const p2 = console.log("Not Promise Method"); | |
const p3 = testPromise(2,10); | |
const p4 = testPromise(3,2); | |
Promise.all([p1, p2, p3, p4]) | |
.then((results) => results.forEach((result) => console.log("Success: " + result))) | |
.catch((err) => console.log("Error: " + err)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment