Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mapAsynchronously = (array, fn, chunksize) => {
  2.     const processChunk = (chunk) => new Promise(resolve => {
  3.         setTimeout(() => resolve(fn(chunk)), 0);
  4.     });
  5.     let promise = Promise.resolve([]);
  6.     for(let i = 0; i < array.length; i += chunksize) {
  7.         const j = i + chunksize;
  8.         promise = promise.then(results => {
  9.             return processChunk(array.slice(i, j))
  10.             .then(result => results.concat(result))
  11.         });
  12.     }
  13.     return promise;
  14. };
  15. (async() => {
  16.     dataFormatted = await mapAsynchronously(cmtAllRawdataDB[0].rows, array => array.map(elm => new Message(elm, configResult)), 100);
  17. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement