Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. async doSomethingWithBigArray(bigArray) {
  2. const arrayBatch = [];
  3. const batchSize = 30;
  4. while (bigArray.length > 0) arrayBatch.push(bigArray.splice(0, batchSize));
  5.  
  6. for (let i = 0; i < arrayBatch.length; i++) {
  7. const batch = arrayBatch[i];
  8. await Promise.all(batch.map(async (arrayItem) => {
  9. await this.doSomethingWithItem(arrayItem);
  10. }));
  11.  
  12. bigArray.push(...batch);
  13. }
  14.  
  15. return bigArray;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement