(items, concurrency, worker)
| 343 | } |
| 344 | |
| 345 | async function runPool(items, concurrency, worker) { |
| 346 | let cursor = 0; |
| 347 | const workers = Array.from({ length: Math.min(concurrency, items.length) }, async () => { |
| 348 | while (cursor < items.length) { |
| 349 | const index = cursor; |
| 350 | cursor += 1; |
| 351 | await worker(items[index], index); |
| 352 | } |
| 353 | }); |
| 354 | await Promise.all(workers); |
| 355 | } |
| 356 | |
| 357 | async function downloadImage(url) { |
| 358 | const response = await fetch(url, { |