Skip to content

Instantly share code, notes, and snippets.

@jkusachi
Created September 15, 2016 18:34
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 jkusachi/6ed6e859731b55b522e42cd21fed29f0 to your computer and use it in GitHub Desktop.
Save jkusachi/6ed6e859731b55b522e42cd21fed29f0 to your computer and use it in GitHub Desktop.
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