How to implement an efficient WhenEach that streams an IAsyncEnumerable of task results?

后端 未结 4 943
闹比i
闹比i 2021-01-01 04:32

I am trying to update my toolset with the new tools offered by C# 8, and one method that seems particularly useful is a version of Task.WhenAll that returns an IAsyncEnumera

4条回答
  •  一整个雨季
    2021-01-01 05:16

    Just for the fun of it, using System.Reactive and System.Interactive.Async:

    public static async IAsyncEnumerable WhenEach(
        Task[] tasks)
        => Observable.Merge(tasks.Select(t => t.ToObservable())).ToAsyncEnumerable()
    

提交回复
热议问题