(
items: T[],
concurrency: number,
fn: (item: T) => Promise<R>
)
| 1060 | } |
| 1061 | |
| 1062 | private async processWithConcurrency<T, R>( |
| 1063 | items: T[], |
| 1064 | concurrency: number, |
| 1065 | fn: (item: T) => Promise<R> |
| 1066 | ): Promise<R[]> { |
| 1067 | const results: R[] = []; |
| 1068 | let index = 0; |
| 1069 | |
| 1070 | async function worker() { |
| 1071 | while (index < items.length) { |
| 1072 | const i = index++; |
| 1073 | results[i] = await fn(items[i]); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | const workers = Array.from({ length: Math.min(concurrency, items.length) }, () => worker()); |
| 1078 | await Promise.all(workers); |
| 1079 | return results; |
| 1080 | } |
| 1081 | } |
no test coverage detected