Created
January 15, 2017 12:47
-
-
Save syaau/408df51d693e5bf19918d651996e5139 to your computer and use it in GitHub Desktop.
Check if Promise.all with large number of items works or not
This file contains 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
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