Sometimes we need to implement IObservable interface. So, we need to handle onNext, onCompleted and onError methods manually. Then, we return a IDisposable object from our own implemented Subscribe method. But, unsubscribed or memory management do not work if we return something like Disposable.Empty from Subscribe method. How to handle this issue. Thanks.
Asked
Active
Viewed 49 times
0
-
4What exactly is your question? There is an example on [MSDN](https://learn.microsoft.com/en-us/dotnet/api/system.iobservable-1?view=netframework-4.7.2) – CodingYoshi Dec 16 '18 at 19:32
-
Actually i want to pass a non-lambda observer as parameter for subscribe method. Then, i want to call an async method with a callback inside subscribe method. So, i dont need any list of observers. So, do i need to do only only return Disposable.Empty as return value of Subscribe method? – user3127212 Dec 16 '18 at 22:02
-
2What have you tried and how did it fail? Can you show some code? – Paulo Morgado Dec 17 '18 at 07:41
-
1@user3127212 - You should never return `Disposable.Empty`. Never ever. You should also never implement `IObservable
` (nor `IObserver – Enigmativity Dec 17 '18 at 10:18`). They are notoriously difficult to get right. Also your statement "unsubscribed or memory management do not work" doesn't make sense in a memory managed environment. You really need to post your code and ask a specific question relating to that code to get a good response.