如何比较以下两者?Rx 更强大吗?
反应式扩展:
var observable = Observable.Create<char>(async (observer, cancel) =>
{
while (true)
{
string line = await sr.ReadLineAsync();
if (line == null)
break;
observer.OnNext(line);
}
});
observable.Subscribe(
c => Console.WriteLine(c.ToString()),
() => end.Dispose());
异步流:
public async void Run(string path)
{
await foreach (var line in TestAsync())
{
Console.WriteLine(line);
}
}
private async IAsyncEnumerable<string> TestAsync()
{
while (true)
{
string line = await sr.ReadLineAsync();
if (line == null)
break;
yield return line;
}
}