开发者

Can IObservable.Catch continue with the same observable

Suppose a have an IObservable:

IObservable<long> obs = ...;

Can I do the following to guarantee that the observable will never ever stop?

IObservable<long> resilientObs = obs.Catch(obs);

So when an exception is caught, c开发者_如何转开发ontinue with the same sequence that generated the exception.


You can only do this with a Cold observable (i.e. an Observable that returns a new sequence every time)

obs.Retry();

But even then, you're not "resuming" an Observable, you're just restarting it.

If you wanted to maintain a persistent connection (say, a web socket that gets terminated because of an error), you need a factory function + Defer:

Observable.Defer(() => createNewObservable())
    .Retry();

To give you better advice, you need to tell us the nature of what obs is and what you're trying to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜