反应性扩展基于特定数目的并行处理 [英] Reactive Extensions Parallel processing based on specific number

查看:86
本文介绍了反应性扩展基于特定数目的并行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的无功扩展。我有对象采集和调用一个方法为每个对象和方法返回布尔。相反,通过每个使用每个回路并调用方法循环的,有没有办法无扩展可同时调用(fork和join)方法的对象(例如5在一个给定的数字时间)后第一个完成,6应该调用方法,它应该继续下去,直到所有的对象都做了。

我AP preciate你的回应。

解决方案

 的IObservable<布尔> someBoolAsyncMethod(SomeObject O)

someCollection.ToObservable()
    。选择(X => Observable.Defer(()=>
        someBoolAsyncMethod(X)。选择(Y =>新建{项= X,结果= Y})))
    .Merge(5)
    .ToList()
    .Subscribe(newListOfBools);
 

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.

解决方案

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);

这篇关于反应性扩展基于特定数目的并行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆