转换 Task<IAsyncEnumerable<T>> 为 IAsyncEnumerable<T>
标签:highlight return bsp sharp ati false his ret div
这么做还是有一些意义的,避免重复处理Task实在是有些复杂,如果代码还要处理IAsyncEnumerable的话尤为如此,将二者统一还是有一定意义的
#region AsAsyncEnumerable
public static async IAsyncEnumerable AsAsyncEnumerable(this System.Threading.Tasks.ValueTask> asyncEnumerable)
{
await foreach (var one in await asyncEnumerable.ConfigureAwait(false))
{
yield return one;
}
}
public static async IAsyncEnumerable AsAsyncEnumerable(this System.Threading.Tasks.ValueTask> asyncEnumerable)
{
foreach (var one in await asyncEnumerable.ConfigureAwait(false))
{
yield return one;
}
}
public static async IAsyncEnumerable AsAsyncEnumerable(this System.Threading.Tasks.Task> asyncEnumerable)
{
foreach (var one in await asyncEnumerable.ConfigureAwait(false))
{
yield return one;
}
}
public static async IAsyncEnumerable AsAsyncEnumerable(this System.Threading.Tasks.Task> asyncEnumerable)
{
await foreach(var one in await asyncEnumerable.ConfigureAwait(false))
{
yield return one;
}
}
#endregion
转换 Task> 为 IAsyncEnumerable
标签:highlight return bsp sharp ati false his ret div
原文地址:https://www.cnblogs.com/yinyue200/p/12678740.html
评论