我是 RX 新手,一直在研究错误处理和重试的使用;我有以下内容(是的,我知道这不是一个“真正的”单元测试,但它给了我摆弄的地方!!)并且想知道我如何去保持重试但能够记录任何异常?
[Test]
public void Test()
{
var scheduler = new TestScheduler();
var source = scheduler.CreateHotObservable(
new Recorded<Notification<long>>(10000000, Notification.CreateOnNext(0L)),
new Recorded<Notification<long>>(20000000, Notification.CreateOnNext(1L)),
new Recorded<Notification<long>>(30000000, Notification.CreateOnNext(2L)),
new Recorded<Notification<long>>(30000001, Notification.CreateOnError<long>(new Exception("Fail"))),
new Recorded<Notification<long>>(40000000, Notification.CreateOnNext(3L)),
new Recorded<Notification<long>>(40000000, Notification.CreateOnCompleted<long>())
);
source.Retry().Subscribe(
l => Console.WriteLine($"OnNext {l}"),
exception => Console.WriteLine(exception.ToString()), // Would be logging this in production
() => Console.WriteLine("OnCompleted"));
scheduler.Start(
() => source,
0,
TimeSpan.FromSeconds(1).Ticks,
TimeSpan.FromSeconds(5).Ticks);
}
这导致...
OnNext 0
OnNext 1
OnNext 2
OnNext 3
OnCompleted
...这正是我想要发生的事情,除了我想记录发生在 2 和 3 之间的异常。
有没有办法让订阅者在 OnError 中看到异常(并记录它),然后重新订阅以便它看到 3?
谢谢!