Skip to content

Instantly share code, notes, and snippets.

View maartenbusstra's full-sized avatar
👻
Boo!

Maarten Busstra maartenbusstra

👻
Boo!
View GitHub Profile

Keybase proof

I hereby claim:

  • I am maartenbusstra on github.
  • I am maartenbusstra (https://keybase.io/maartenbusstra) on keybase.
  • I have a public key whose fingerprint is DE19 14FD E115 1C11 C080 D5F9 99DD 44BE 8431 FE3B

To claim this, I am signing this object:

@maartenbusstra
maartenbusstra / batched-map.js
Last active April 14, 2019 02:44
Perform async map in batches
const batchedMap = batchSize => data => async (fn) => {
const batches = data.length / batchSize;
let result = [];
for (let i = 0; i < batches; i++) {
const res = await Promise.all(data
.slice(i * batchSize, (i + 1) * batchSize)
.map((d, j) => fn(d, (i * batchSize) + j)),
);
result = result.concat(res);
}