Member Junction
    Preparing search index...

    Function RunMaybeSerial

    • Runs a list of save/work factories with transaction-aware concurrency:

      • If provider.IsInTransaction is true, runs them sequentially via await (no microtask interleaving, no contention on the single transaction-bound connection).
      • Otherwise, fans them out concurrently via Promise.all.

      Use this anywhere you would normally write Promise.all(items.map(save)) but a single shared transaction is in flight. The PostgreSQL provider holds its active transaction on a single pg.PoolClient, so concurrent Save() calls would queue up on that one client anyway — and worse, combined with non-DB async work (e.g. embedding compute), the queue can deadlock. Sequential execution avoids that entirely.

      SQL Server preserves the original parallelism: IsInTransaction is false by default on DatabaseProviderBase, and the SQL Server provider doesn't override it.

      Pass factory functions (() => Promise<T>) rather than already-started promises so saves only start when we're ready to await them.

      Type Parameters

      • T

      Parameters

      • provider: unknown

        — the active data provider (used to read transaction state)

      • factories: (() => Promise<T>)[]

        — work units to run; each is invoked when its turn comes

      Returns Promise<T[]>

      the results in input order