concurrency.ts

Internal concurrency helpers — bounded Promise.all for the few sites where unbounded fan-out would risk resource exhaustion.

  • MAX_FILE_CONCURRENCY — parallel readFile cap. Bounds FD pressure so projects with thousands of source files don't trip EMFILE against the typical 1024-FD ulimit. Used by files.globFiles, exports.discoverFromExports, and the session's context-closure reads.
  • MAX_RESOLVE_CONCURRENCY — parallel resolver-call cap for session phase 2. Async resolvers (Vite/Rollup resolveId, user-supplied) get backpressure instead of a 20k+ task fan-out at once. Sync resolvers (TS default, no-deps stub) settle in microtasks regardless of the bound. Also bounds healUnresolvedEdges retries.
  • mapConcurrent — order-preserving, fail-fast worker pool applying either cap.

Same numerical value today, separately named so a future tuning pass can move them independently (FD pressure and resolver backpressure are unrelated limits that happen to coincide at this cap).

view source

Declarations
#

3 declarations

mapConcurrent
#

concurrency.ts view source

<T, R>(items: readonly T[], concurrency: number, fn: (item: T, index: number) => Promise<R>): Promise<R[]> import {mapConcurrent} from 'svelte-docinfo/concurrency.js';

Maps over items with a bounded number of in-flight promises, preserving input order.

Fail-fast: when fn rejects, the outer promise rejects with that error and idle workers stop pulling from the queue (already-in-flight fn calls run to completion — there's no AbortSignal plumbing). Subsequent rejections from in-flight calls are swallowed by Promise.all (only the first wins), so a misbehaving fn can't surface a second error after the function returns.

items

input array

type readonly T[]

concurrency

maximum number of concurrent operations

type number

fn

mapping function (receives item and index)

type (item: T, index: number) => Promise<R>

returns

Promise<R[]>

array of results in input order

generics

mapConcurrent<T, R>
T
R

MAX_FILE_CONCURRENCY
#

MAX_RESOLVE_CONCURRENCY
#

Imported by
#