( concurrency: number, items: T[], processItem: (item: T) => Promise<R> )
| 1 | export async function queue<T, R>( |
| 2 | concurrency: number, |
| 3 | items: T[], |
| 4 | processItem: (item: T) => Promise<R> |
| 5 | ) { |
| 6 | const workers = [...new Array(concurrency)]; |
| 7 | await Promise.all( |
| 8 | workers.map(async (_, index) => { |
| 9 | let count = 0; |
| 10 | while (true) { |
| 11 | const item = items.pop(); |
| 12 | if (!item) { |
| 13 | break; |
| 14 | } |
| 15 | await processItem(item); |
| 16 | count++; |
| 17 | } |
| 18 | }) |
| 19 | ); |
| 20 | } |
no outgoing calls
no test coverage detected