MCPcopy
hub / github.com/codedogQBY/ReadAny / parallelLimit

Function parallelLimit

packages/core/src/sync/sync-transfer.ts:4–22  ·  view source on GitHub ↗
(tasks: (() => Promise<T>)[], limit: number)

Source from the content-addressed store, hash-verified

2 * Helper: Run tasks in parallel with concurrency limit
3 */
4export async function parallelLimit<T>(tasks: (() => Promise<T>)[], limit: number): Promise<T[]> {
5 const results: T[] = [];
6 const executing: Promise<void>[] = [];
7
8 for (const task of tasks) {
9 const p = task().then((result) => {
10 results.push(result);
11 executing.splice(executing.indexOf(p), 1);
12 });
13 executing.push(p);
14
15 if (executing.length >= limit) {
16 await Promise.race(executing);
17 }
18 }
19
20 await Promise.all(executing);
21 return results;
22}

Callers 4

runFileTasksFunction · 0.90
syncFilesFunction · 0.90
cleanupRemoteOrphansFunction · 0.90
cleanupLocalOrphansFunction · 0.90

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected