首页 > 解决方案 > 响应式 .NET (RX) 通过返回相同的 Observable 嵌套捕获

问题描述

我想介绍一些特定的错误捕获例程,然后重试订阅相同的 observable。这有什么缺点吗:

 public static IObservable<int> GetObservable()
{
  return Observable.Interval(TimeSpan.Zero)
    .Select(x =>
    {
      Console.WriteLine($"Throwing");
      throw new Exception("ups");

      return Observable.Return(1);
    }).SelectMany(x => x)
    .Catch<int, Exception>(ex =>
    {
      return GetObservable().SubscribeOn(Scheduler.Default);
    });
}

Catch 是否真的有一些东西,不应该以这种方式使用?有什么影响?是否应该将Catch其视为“使用一次”例程,Do然后在底部使用时进行异常检查Retry

标签: c#exceptionsystem.reactive

解决方案


推荐阅读