我想在并行任务/等待中使用.NET迭代器。类似于这样:
IEnumerable<TDst> Foo<TSrc, TDest>(IEnumerable<TSrc> source)
{
Parallel.ForEach(
source,
s=>
{
// Ordering is NOT important
// items can be yielded as soon as they are done
yield return ExecuteOrDownloadSomething(s);
}
}
很遗憾,.NET不能在本地处理此操作。迄今为止,@svick的最佳答案是使用AsParallel()。
额外奖励:是否有任何简单的async/await代码实现多个发布者和一个订阅者? 订阅者将会产生,而出版物将会被处理。(仅限核心库)