import { chunk } from 'lodash' export const chunkedEach = async ( values: Array, size: number, callback: (value: T, index: number, array: Array) => Promise, throwErrors = true, ): Promise => { const chunked = chunk(values, size) for (const array of chunked) { await Promise.all( array.map(async (value: T, index: number, originalArray: Array) => { if (!throwErrors) return await callback(value, index, originalArray) try { return await callback(value, index, originalArray) } catch (error) { console.error(error) } }), ) } }