( items: T[], limit: number, worker: (item: T, index: number) => Promise<U> )
| 2455 | } |
| 2456 | |
| 2457 | async function mapLimit<T, U>( |
| 2458 | items: T[], |
| 2459 | limit: number, |
| 2460 | worker: (item: T, index: number) => Promise<U> |
| 2461 | ): Promise<U[]> { |
| 2462 | const results = new Array<U>(items.length) |
| 2463 | let nextIndex = 0 |
| 2464 | |
| 2465 | const run = async (): Promise<void> => { |
| 2466 | while (nextIndex < items.length) { |
| 2467 | const index = nextIndex |
| 2468 | nextIndex += 1 |
| 2469 | results[index] = await worker(items[index], index) |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | const workers = Array.from( |
| 2474 | { length: Math.min(limit, items.length) }, |
| 2475 | () => run() |
| 2476 | ) |
| 2477 | await Promise.all(workers) |
| 2478 | return results |
| 2479 | } |
| 2480 | |
| 2481 | /** |
| 2482 | * Walk every directory under the three top-level folders and return a |
no test coverage detected