/** * Concurrency helpers. * * Internal only — deliberately not re-exported from `core/index.ts`, so it is * not part of the published API surface. * * Leaf module: depends on nothing inside the SDK, so it is safe to import from * any layer without forming a cycle (see CLAUDE.md §9). */ /** * Map over `items` running at most `limit` tasks at a time. * * Exists because `Promise.all` over a caller-sized array is unbounded: a vault * with 40 borrowers opens 40 simultaneous connections to the same backend, * which is how a slow endpoint turns into a timeout storm rather than a slow * response. A small fixed window keeps latency close to the parallel case while * bounding the load the SDK can put on one origin. * * Results preserve input order regardless of completion order. A rejected task * rejects the returned promise (like `Promise.all`); callers that need * per-item error isolation should catch inside `task`. * * @param items - Inputs to process. An empty array resolves to `[]` immediately. * @param limit - Maximum tasks in flight. Values below 1 are treated as 1. * @param task - Receives an item and its index; returns the value for that slot. * @returns Results in the same order as `items`. * @throws Whatever `task` rejects with, on the first rejection. * @example * ```ts * // At most 5 concurrent requests, regardless of borrower count. * const positions = await mapWithConcurrency(borrowers, 5, (b) => * fetchPosition(b).catch(() => null), * ); * ``` * @internal */ export declare function mapWithConcurrency(items: readonly TIn[], limit: number, task: (item: TIn, index: number) => Promise): Promise; /** * Race a promise against a timeout so a hung call can't block indefinitely. The * timer is always cleared, so a fast-resolving promise leaves nothing pending. * * @param promise - The call to bound. It keeps running after a timeout; only * the wait is abandoned. * @param ms - Timeout in milliseconds. Values below 0 are treated as 0. * @param label - Names the call in the rejection message. * @returns What `promise` resolves to. * @throws `Error("