我有这个类的解释我的问题:实现Rx处理程序的最佳实践是什么?
public class DataObserver: IDisposable
{
private readonly List<IDisposable> _subscriptions = new List<IDisposable>();
private readonly SomeBusinessLogicServer _server;
public DataObserver(SomeBusinessLogicServer server, IObservable<SomeData> data)
{
_server = server;
_subscriptions.Add(data.Subscribe(TryHandle));
}
private void TryHandle(SomeData data)
{
try
{
_server.MakeApiCallAsync(data).Wait();
}
catch (Exception)
{
// Handle exceptions somehow!
}
}
public void Dispose()
{
_subscriptions.ForEach(s => s.Dispose());
_subscriptions.Clear();
}
}
A)我怎样才能避免TryHandle()函数中阻塞? B)你将如何发布在该函数内捕获的异常以正确处理它们?
顺便提一句,我建议将此文档添加到源代码库 - 如果发生这种情况,我会回复。 –
感谢James给Rx操作员提示。很有帮助。 :-) –