(items, worker, limit)
| 203 | } |
| 204 | |
| 205 | async function mapConcurrent(items, worker, limit) { |
| 206 | const results = []; |
| 207 | let next = 0; |
| 208 | |
| 209 | async function run() { |
| 210 | while (next < items.length) { |
| 211 | const current = next; |
| 212 | next += 1; |
| 213 | results[current] = await worker(items[current], current); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | await Promise.all(Array.from({ length: Math.min(limit, items.length) }, run)); |
| 218 | return results; |
| 219 | } |
| 220 | |
| 221 | async function main() { |
| 222 | console.log( |