Is there a method I can use to set the maximum thread count of an IObservable.SelectMany?
The following code works great for updating the UI as items are processed, but the task I'm trying to execute is a bit of a resource hog at the moment. I would like to set the max threads to like two, to be a bit lighter on resource usage.
AsyncCommand = ReactiveCommand.CreateAsyncObservable(_ =>
{
// Set progress bar indicator to 0
var set = new [] {...} // The set of items to process
// Set the progress bar indicator max to the count of the items to process
return set
.ToObservable()
.SelectMany((item, index) => Task.Run(() =>
{
// Process item
return item;
}), (item, index, processed) => item);
});
AsyncCommand
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(item =>
{
// Step the progress bar indicator
});
Merge
has a max parallelism parameter:See also a more advanced solution