UNPKG

@intlayer/chokidar

Version:

Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.

1 lines 2.9 kB
{"version":3,"file":"parallelizeGlobal.cjs","names":["pLimit"],"sources":["../../../src/utils/parallelizeGlobal.ts"],"sourcesContent":["// === keep your Queue, Node, pLimit, validateConcurrency exactly as-is ===\n\nimport { pLimit } from './pLimit';\n\n// --- NEW: single, shared limiter for the whole process ---\nlet _globalLimiter: ReturnType<typeof pLimit> | null = null;\n\n/** Get (and optionally configure) the single, shared limiter. */\nexport const getGlobalLimiter = (concurrency?: number) => {\n if (!_globalLimiter) {\n _globalLimiter = pLimit(concurrency ?? 10);\n } else if (typeof concurrency === 'number') {\n (_globalLimiter as any).concurrency = concurrency;\n }\n return _globalLimiter!;\n};\n\n// --- NEW: task limiter for gating task starts ---\nlet _taskLimiter: ReturnType<typeof pLimit> | null = null;\n\n/** Limits how many *tasks* run concurrently (independent from AI calls). */\nexport const getTaskLimiter = (concurrency?: number) => {\n if (!_taskLimiter) {\n _taskLimiter = pLimit(concurrency ?? 5);\n } else if (typeof concurrency === 'number') {\n (_taskLimiter as any).concurrency = concurrency;\n }\n return _taskLimiter!;\n};\n\n// --- REPLACE your existing `parallelize` with this version ---\nexport const parallelizeGlobal = async <T, R>(\n items: T[],\n callback: (item: T, index: number) => Promise<R> = async (item) =>\n item as unknown as Promise<R>,\n options?: {\n /** Share a single limiter across the app. If omitted, uses global limiter. */\n limiter?: ReturnType<typeof pLimit>;\n /** If provided and no limiter is passed, configure the global limiter. */\n concurrency?: number;\n /**\n * Whether to wrap *each* callback run in the limiter.\n * - For orchestration (outer loops): set `false` (don't burn limiter slots).\n * - For atomic work (AI calls, writes): leave `true` (default).\n */\n wrapInLimiter?: boolean;\n }\n): Promise<R[]> => {\n const limiter = options?.limiter ?? getGlobalLimiter(options?.concurrency);\n const wrap = options?.wrapInLimiter ?? true;\n\n const run = wrap\n ? <U>(fn: () => Promise<U>) => limiter(fn)\n : <U>(fn: () => Promise<U>) => fn();\n\n const promises = items.map((item, index) => run(() => callback(item, index)));\n return Promise.all(promises);\n};\n"],"mappings":";;;;AAKA,IAAI,iBAAmD;;AAGvD,MAAa,oBAAoB,gBAAyB;CACxD,IAAI,CAAC,gBACH,iBAAiBA,4BAAO,eAAe,EAAE;MACpC,IAAI,OAAO,gBAAgB,UAChC,AAAC,eAAuB,cAAc;CAExC,OAAO;AACT;AAGA,IAAI,eAAiD;;AAGrD,MAAa,kBAAkB,gBAAyB;CACtD,IAAI,CAAC,cACH,eAAeA,4BAAO,eAAe,CAAC;MACjC,IAAI,OAAO,gBAAgB,UAChC,AAAC,aAAqB,cAAc;CAEtC,OAAO;AACT;AAGA,MAAa,oBAAoB,OAC/B,OACA,WAAmD,OAAO,SACxD,MACF,YAYiB;CACjB,MAAM,UAAU,SAAS,WAAW,iBAAiB,SAAS,WAAW;CAGzE,MAAM,MAFO,SAAS,iBAAiB,QAG/B,OAAyB,QAAQ,EAAE,KACnC,OAAyB,GAAG;CAEpC,MAAM,WAAW,MAAM,KAAK,MAAM,UAAU,UAAU,SAAS,MAAM,KAAK,CAAC,CAAC;CAC5E,OAAO,QAAQ,IAAI,QAAQ;AAC7B"}