是否可以将 IObservable<T> 转换为 IAsyncEnumerable<T>

Roo*_*ian 5 c# system.reactive signalr iasyncenumerable

我有一个可观察的IObservable<T>/ISubject<T>并想通过使用 SignalR 返回它。SignalR 具有异步流的概念,您必须在其中返回IAsyncEnumerable<T>.

如何将 an 转换IObservable<T>为 an IAsyncEnumerable<T>

The*_*ias 11

ToAsyncEnumerable程序集中有一个扩展方法System.Linq.Async,可在此处作为 NuGet 包使用。

public static IAsyncEnumerable<TSource> ToAsyncEnumerable<TSource>(
    this IObservable<TSource> source);
Run Code Online (Sandbox Code Playgroud)