MCPcopy Index your code
hub / github.com/simstudioai/sim / mapWithConcurrency

Function mapWithConcurrency

apps/sim/lib/core/utils/concurrency.ts:13–32  ·  view source on GitHub ↗
(
  items: readonly T[],
  limit: number,
  fn: (item: T, index: number) => Promise<R>
)

Source from the content-addressed store, hash-verified

11 * allSettled-style variant rather than letting a throwing mapper through here.
12 */
13export async function mapWithConcurrency<T, R>(
14 items: readonly T[],
15 limit: number,
16 fn: (item: T, index: number) => Promise<R>
17): Promise<R[]> {
18 const results = new Array<R>(items.length)
19 const workerCount = Math.max(1, Math.min(limit, items.length))
20 let cursor = 0
21
22 const worker = async (): Promise<void> => {
23 while (true) {
24 const index = cursor++
25 if (index >= items.length) return
26 results[index] = await fn(items[index], index)
27 }
28 }
29
30 await Promise.all(Array.from({ length: workerCount }, worker))
31 return results
32}
33
34/** Default bound for per-row object-storage materialization fan-out. */
35export const MATERIALIZE_CONCURRENCY = 20

Callers 7

copyForkResourceContentFunction · 0.90
pagesFunction · 0.90
processBackfillPageFunction · 0.90
maskPIIBatchViaHttpFunction · 0.90
maskPIIBatchFunction · 0.90
route.tsFile · 0.90
route.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected