Skip to content

Instantly share code, notes, and snippets.

@syaau
Created January 15, 2017 12:47
Show Gist options
  • Save syaau/408df51d693e5bf19918d651996e5139 to your computer and use it in GitHub Desktop.
Save syaau/408df51d693e5bf19918d651996e5139 to your computer and use it in GitHub Desktop.
Check if Promise.all with large number of items works or not
function generateDocs(count) {
const docs = [];
for (let i = 0; i < count; i += 1) {
docs.push({
id: i + 1,
name: `Name${i}`,
processed: false,
});
};
return docs;
}
function someAsyncOperation(item) {
return new Promise(resolve => {
setTimeout(() => {
resolve(Object.assign({}, item, { processed: true }));
}, Math.random() * 100);
});
};
const docs = generateDocs(500000);
const res = Promise.all(docs.map(doc => someAsyncOperation(doc)));
res.then((r) => {
console.log(r.length, 'done');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment