UNPKG

bookr-cli

Version:

A terminal-based CLI tool to book time in Jira using the Tempo plugin by parsing your current Git branch name

29 lines 970 B
/** * Execute a function on array items with limited concurrency * This implementation avoids stack overflow, race conditions, and type safety issues */ export async function parallelMapLimit(arr, limit, fn) { if (arr.length === 0) { return []; } const results = new Array(arr.length); let nextIndex = 0; // Create a worker function that processes items sequentially const worker = async () => { while (nextIndex < arr.length) { const currentIndex = nextIndex++; const item = arr[currentIndex]; if (item !== undefined) { results[currentIndex] = await fn(item); } } }; // Start the specified number of workers const workers = Array(Math.min(limit, arr.length)) .fill(null) .map(() => worker()); // Wait for all workers to complete await Promise.all(workers); return results; } //# sourceMappingURL=concurrency.js.map