MCPcopy
hub / github.com/donmccurdy/glTF-Transform / pLimit

Function pLimit

packages/cli/src/utils/p-limit.ts:4–18  ·  view source on GitHub ↗
(items: T[], limit: number, fn: PLimitFn<T>)

Source from the content-addressed store, hash-verified

2
3/** Runs multiple async functions, with limited concurrency. */
4export async function pLimit<T>(items: T[], limit: number, fn: PLimitFn<T>): Promise<void> {
5 // Iterate values in order, 0–N.
6 items = items.slice().reverse();
7
8 let index = 0;
9
10 // Spawn 'limit' concurrent functions.
11 await Promise.all(
12 [...Array(limit)].map(async () => {
13 while (items.length > 0) {
14 await fn(items.pop()!, index++);
15 }
16 }),
17 );
18}

Callers 3

util.test.tsFile · 0.90
ktxdecompressFunction · 0.85
toktxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected