Created
September 15, 2016 18:34
-
-
Save jkusachi/6ed6e859731b55b522e42cd21fed29f0 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
var counter = { x: 0 }; | |
var p = []; | |
function count(c) { | |
var time = Math.floor(Math.random() * 1000); | |
return new Promise(function (resolve) { | |
setTimeout(function () { | |
var x = c.x++; | |
console.log(x + ':' + time); | |
resolve(x + ':' + time); | |
}, time); | |
}); | |
} | |
for (var i = 0; i < 1000; i++) { | |
p.push(count(counter)); | |
} | |
Promise.all(p).then(console.log.bind(console)); | |
4,000,000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment