Skip to content

Instantly share code, notes, and snippets.

@jkusachi

jkusachi/timer.js

Created Sep 15, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.