Continue using subscription after exception

橙三吉。 提交于 2019-12-07 03:31:30

The Catch operator helps here.

In your code, I think you could do this to prevent the subscription from ending when searchAsync fails:

var searchAsync = Observable
    .FromAsyncPattern<string, object>(getDataFunc.BeginInvoke, getDataFunc.EndInvoke)
    .Catch(e => Observable.Empty<object>()) // eat the error and return "no results" for this search.

You can return any new observable you want. You could log the error and return another search attempt. In this case I just return an empty observable which make the overall subscription behave as if that search attempt had never happened.

I was misunderstanding Rx. A sequence once it gets faulted it can not be reused. The simple solution is to recreate the subscription(s), i.e.: call again SetupObserver()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!