Reactive Extensions Parallel processing based on specific number

只愿长相守 提交于 2019-12-05 09:25:38

问题


I'm new to Reactive Extensions. I have objects collection and call a method for each object and method returns Boolean. Instead of looping through each by using for each loop and calling the method, is there a way in reactive extensions to call concurrently(fork and join) the method for a given number of objects(ex 5 at a time) and after first one done, 6th one should call method and it should continue until all the objects are done.

I appreciate your response.


回答1:


IObservable<bool> someBoolAsyncMethod(SomeObject o)

someCollection.ToObservable()
    .Select(x => Observable.Defer(() => 
        someBoolAsyncMethod(x).Select(y => new { Item = x, Result = y})))
    .Merge(5)
    .ToList()
    .Subscribe(newListOfBools);


来源:https://stackoverflow.com/questions/10178683/reactive-extensions-parallel-processing-based-on-specific-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!