p-map icon indicating copy to clipboard operation
p-map copied to clipboard

Allow dynamically changing the concurrency

Open sindresorhus opened this issue 4 years ago • 3 comments

The idea was brought up in #28.

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

sindresorhus avatar Feb 21 '21 13:02 sindresorhus

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
	}

	// ...
}

Richienb avatar Jun 09 '21 09:06 Richienb

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

sindresorhus avatar Jun 09 '21 09:06 sindresorhus

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

Richienb avatar Jun 09 '21 09:06 Richienb