我阅读了以下代码。代码中的Util.KeepRunning()
是什么?似乎是在等待异步方法完成。但是为什么它需要一次性使用?
var observable = Observable.Create<char>(async (observer, cancel) =>
{
for (var i = 0; !cancel.IsCancellationRequested && i < 100; i++)
{
observer.OnNext(await GetCharAsync());
}
});
//Here's how you can use it in LINQPad, for example:
// Create a disposable that keeps the query running.
// This is necessary, since the observable is 100% async.
var end = Util.KeepRunning();
observable.Subscribe(
c => Console.WriteLine(c.ToString()),
() => end.Dispose());