WebApiWithBackgroundWorker icon indicating copy to clipboard operation
WebApiWithBackgroundWorker copied to clipboard

how to change the number of consumers in the runtime

Open dollhead opened this issue 4 years ago • 1 comments

Hi, thanks for a nice series of articles!

I am designing an app with a similar usage of channels for producer/consumer scenarios. Your solution looks very good, so I borrowed a couple of tweaks from it, thanks :)

However, I have a requirement that the number of in-progress tasks(so, number of consumer instances in this case) should be adjustable at the runtime. Any thoughts on how it could be achieved? I'm wondering how we can safely inject/pull out consumers, but did not come out with an elegant solution yet.

dollhead avatar Jun 01 '20 09:06 dollhead

hi, and thanks for reading! You could try injecting a service in the Background worker, acting as proxy between it and the consumers. Inside this new service, you could try listening for an event informing you when this number of in-progress tasks changes, and if so, adjust the consumers accordingly.

mizrael avatar Jun 01 '20 13:06 mizrael