Skip to content

Instantly share code, notes, and snippets.

@hail2u
Created May 7, 2020 14:23

Revisions

  1. hail2u created this gist May 7, 2020.
    22 changes: 22 additions & 0 deletions split-promise-all.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    const to8Chunks = (previous, current, index) => {
    const remainder = index % 8;

    if (!previous[remainder]) {
    previous.push([]);
    }

    previous[remainder].push(current);
    return previous;
    };

    const main = async () => {
    const hugeArray = [];
    const hugeChunks = hugeArray.reduce(to8Chunks, []);
    let r = [];

    for (const hugeChunk of hugeChunks) {
    r = r.concat(await Promise.all(hugeChunk.map(doSomething)));
    }
    };

    main();