MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / runPool

Function runPool

apps/api/e2e/lib.ts:212–226  ·  view source on GitHub ↗
(
  items: T[],
  concurrency: number,
  fn: (item: T, index: number) => Promise<void>
)

Source from the content-addressed store, hash-verified

210
211/** Run `fn` over `items` with at most `concurrency` in flight. */
212export async function runPool<T>(
213 items: T[],
214 concurrency: number,
215 fn: (item: T, index: number) => Promise<void>
216): Promise<void> {
217 let next = 0;
218 const workers = Array.from({ length: Math.min(concurrency, items.length) }, async () => {
219 while (true) {
220 const i = next++;
221 if (i >= items.length) return;
222 await fn(items[i]!, i);
223 }
224 });
225 await Promise.all(workers);
226}
227
228export async function shutdown(failed: number): Promise<never> {
229 await redis.quit().catch(() => {});

Callers 1

emitFunction · 0.90

Calls 2

fnFunction · 0.85
fromMethod · 0.45

Tested by

no test coverage detected