UNPKG

diginext-utils

Version:
17 lines (16 loc) 642 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); async function batchProcessor(list, callback, batchSize = 10) { let res = []; // Function to process a single batch async function processBatch(batch) { return await Promise.all(batch.map((item) => callback(item))); } // Divide the list into batches for (let i = 0; i < list.length; i += batchSize) { const batch = list.slice(i, i + batchSize); res = [...res, ...(await processBatch(batch))]; // Process each batch and wait for it to complete } return res; } exports.default = batchProcessor;