(concurrency: number, items: T[], fn: (item: T) => Promise<void>)
| 19 | } |
| 20 | |
| 21 | export async function work<T>(concurrency: number, items: T[], fn: (item: T) => Promise<void>) { |
| 22 | const pending = [...items] |
| 23 | await Promise.all( |
| 24 | Array.from({ length: concurrency }, async () => { |
| 25 | while (true) { |
| 26 | const item = pending.pop() |
| 27 | if (item === undefined) return |
| 28 | await fn(item) |
| 29 | } |
| 30 | }), |
| 31 | ) |
| 32 | } |
no test coverage detected