sindresorhus / p-map

Map over promises concurrently
MIT License
1.27k stars 58 forks source link

Allow dynamically changing the concurrency #33

Open sindresorhus opened 3 years ago

sindresorhus commented 3 years ago

The idea was brought up in #28.

Not entirely sure what the best API would be for this though. Feedback welcome.

Richienb commented 3 years ago

If mapper returns something like pMap.setConcurrency(5) then it should set the concurrency value in memory and then spin up more calls to next() as needed. Already running next() chains should check if they are not needed anymore at the start of each iteration:

const next = id => {
    if (concurrency < id) {
        return
    }

    // ...
}
sindresorhus commented 3 years ago

pMap.setConcurrency(5) would need to include the actual value too though.

Richienb commented 3 years ago

Yes. It would work in a similar way to pMap.stop.