MCPcopy
hub / github.com/lingodotdev/lingo.dev / execAsync

Function execAsync

packages/cli/src/cli/utils/exec.ts:17–43  ·  view source on GitHub ↗
(
  fns: (() => Promise<any>)[],
  options: ExecAsyncOptions = ExecAsyncSchema.parse({}),
)

Source from the content-addressed store, hash-verified

15 * @param options Options
16 */
17export async function execAsync(
18 fns: (() => Promise<any>)[],
19 options: ExecAsyncOptions = ExecAsyncSchema.parse({}),
20) {
21 const limit = pLimit(options.concurrency);
22 const limitedFns = fns.map((fn) => () => limit(fn));
23
24 const resultPromises: Promise<any>[] = [];
25
26 let completedCount = 0;
27 options.onProgress?.(completedCount, limitedFns.length);
28
29 for (let i = 0; i < limitedFns.length; i++) {
30 const fn = limitedFns[i];
31 const resultPromise = fn().then((result) => {
32 completedCount++;
33 options.onProgress?.(completedCount, limitedFns.length);
34 return result;
35 });
36 resultPromises.push(resultPromise);
37
38 await Promise.race([resultPromise, delay(options.delay)]);
39 }
40
41 const results = await Promise.all(resultPromises);
42 return results;
43}
44
45export type ExecWithRetryOptions = Z.infer<typeof ExecWithRetrySchema>;
46

Callers 5

exec.spec.tsFile · 0.90
prepareAllFixturesFunction · 0.85
prepareFixtureFunction · 0.85
killProcessTreeFunction · 0.85
buildFunction · 0.85

Calls 4

fnFunction · 0.85
delayFunction · 0.85
parseMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected