【问题标题】:Is it possible to transform an IObservable<T> to an IAsyncEnumerable<T>是否可以将 IObservable<T> 转换为 IAsyncEnumerable<T>
【发布时间】:2020-03-13 16:01:42
【问题描述】:
我有一个可观察的 IObservable<T> / ISubject<T> 并希望使用 SignalR 将其返回。 SignalR 具有异步流的概念,您必须在其中返回 IAsyncEnumerable<T>。
如何将IObservable<T> 转换为IAsyncEnumerable<T>?
【问题讨论】:
标签:
c#
signalr
system.reactive
iasyncenumerable
【解决方案1】:
System.Linq.Async 程序集中有一个 ToAsyncEnumerable 扩展方法,可作为 NuGet 包 here 提供。
public static IAsyncEnumerable<TSource> ToAsyncEnumerable<TSource>(
this IObservable<TSource> source);