Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mapAsynchronously = (array, fn, chunksize) => {
- const processChunk = (chunk) => new Promise(resolve => {
- setTimeout(() => resolve(fn(chunk)), 0);
- });
- let promise = Promise.resolve([]);
- for(let i = 0; i < array.length; i += chunksize) {
- const j = i + chunksize;
- promise = promise.then(results => {
- return processChunk(array.slice(i, j))
- .then(result => results.concat(result))
- });
- }
- return promise;
- };
- (async() => {
- dataFormatted = await mapAsynchronously(cmtAllRawdataDB[0].rows, array => array.map(elm => new Message(elm, configResult)), 100);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement