相关疑难解决方法(0)

将IEnumerable <Task <T >>转换为IObservable <T>

我正在尝试使用Reactive Extensions(Rx)在任务完成时缓冲它们的枚举.有谁知道是否有一个干净的内置方式这样做?该ToObservable扩展方法只会让一IObservable<Task<T>>,这不是我想要的,我想要的IObservable<T>,我可以再使用Buffer的.

举例:

//Method designed to be awaitable
public static Task<int> makeInt()
{
     return Task.Run(() => 5);
}

//In practice, however, I don't want to await each individual task
//I want to await chunks of them at a time, which *should* be easy with Observable.Buffer 
public static void Main() 
{
    //Make a bunch of tasks
    IEnumerable<Task<int>> futureInts = Enumerable.Range(1, 100).Select(t => makeInt());

    //Is there a built in way to turn this into …
Run Code Online (Sandbox Code Playgroud)

.net c# task-parallel-library system.reactive

6
推荐指数
1
解决办法
1043
查看次数

标签 统计

.net ×1

c# ×1

system.reactive ×1

task-parallel-library ×1