Files
刘宇飞 6e0a1fbcbb Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 15:37:45 +08:00

22 lines
768 B
JavaScript

/* eslint-disable valid-jsdoc */
/**
* Maps each value of an array into an async function, and returns an array of the results
* @template In
* @template Out
* @param {In[]} arr - array of values
* @param {number} batchSize - number of calls to `func` to do at one time
* @param {(value: In) => Promise<Out>} func - async function to apply to all items in `arr`. Takes one argument.
* @return {Promise<Out[]>} - results of `func` applied to each item in `arr`
*/
exports.batchMap = async (arr, batchSize, func) => {
const results = [];
for (let i = 0; i < arr.length; i += batchSize) {
const result = await Promise.all(
arr.slice(i, i + batchSize).map(func)
);
results.push(...result);
}
return results;
};