UNPKG

@tmlmobilidade/utils

Version:

A collection of utility functions and helpers for the TML Mobilidade Go monorepo, providing common functionality for batching operations, caching, HTTP requests, object manipulation, permissions, and more.

24 lines (23 loc) 738 B
/** * Performs an operation on large array of data in chunks. * @param data The data to be processed in chunks. * @param operation The operation to be performed on each chunk of data. * @param chunkSize The size of each chunk. Defaults to 5000. */ export async function performInChunks(data, operation, chunkSize = 5000) { // // // Define an array to hold arrays of data (called chunks). const allChunksOfData = []; // // Split the orignal data into chunks for (let i = 0; i < data.length; i += chunkSize) { allChunksOfData.push(data.slice(i, i + chunkSize)); } // // Process each chunk of data for (const chunk of allChunksOfData) { await operation(chunk); } // }