| 49 | } |
| 50 | |
| 51 | async function mapWithConcurrency<T>( |
| 52 | items: T[], |
| 53 | concurrency: number, |
| 54 | mapper: (item: T) => Promise<void> |
| 55 | ): Promise<void> { |
| 56 | if (items.length === 0) return |
| 57 | const workerCount = Math.min(concurrency, items.length) |
| 58 | let cursor = 0 |
| 59 | |
| 60 | const workers = Array.from({ length: workerCount }, async () => { |
| 61 | while (true) { |
| 62 | const index = cursor++ |
| 63 | if (index >= items.length) return |
| 64 | await mapper(items[index]) |
| 65 | } |
| 66 | }) |
| 67 | |
| 68 | await Promise.all(workers) |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Parse a .pptx file buffer and extract all relevant files, categorized by type. |