/**
 * Import batch runner — the cancellable core of the `/api/repos/:repo/import`
 * dispatcher loop, extracted so it's unit-testable without a live Fastify
 * socket.
 *
 * Files are processed in batches of `concurrency`. Before each batch the runner
 * checks `isAborted()`; once the client has disconnected (AbortController on the
 * web side), it stops dispatching further batches and returns what completed.
 * It NEVER abandons in-flight work mid-batch — the current batch always settles
 * — so the route's existing batched `commitPending` commits exactly the entries
 * that finished, keeping the commit-pipeline invariant (no uncommitted files)
 * intact. Cancel is partial + honest: import is additive and collision-safe, so
 * committing the completed prefix and reporting "N of M" is correct.
 */
export async function runImportBatches(files, processFile, opts) {
    const concurrency = Math.max(1, opts.concurrency);
    const results = [];
    let cancelled = false;
    for (let i = 0; i < files.length; i += concurrency) {
        // Check between batches — not mid-batch — so the in-flight batch always
        // settles and its entries are committable. Stopping mid-Promise.all
        // would risk a half-written entry the commit step never sees.
        if (opts.isAborted?.()) {
            cancelled = true;
            break;
        }
        const batch = files.slice(i, i + concurrency);
        const batchResults = await Promise.all(batch.map(processFile));
        results.push(...batchResults);
    }
    return { results, cancelled };
}
//# sourceMappingURL=import-batch.js.map