I have subscribed an Observable with high frequency of pushing content, these content are from network I/O, so each pushing was originally from different thread, then I have some observers are likely try to get some content and then unsubscribe quickly to make sure there's no other content incoming, so the code sample is like:
IDisposable dsp = null;
dsp = TargetObservable.Subscribe((incomingContent) =>
{
if (incomingContent == "something")
{
myList.Add(incomingContent);
dsp.Dispose();
}
else
{
otherList.Add(incomingContent);
}
});
For now, the OnNext obviously is not thread safe, means when the Observer get the "something" and right before the calling Dispose(), other content may still incoming and added to 'otherList', even I put a 'lock(...)' for the whole 'onNext(...)'.
This is not we want, so any idea to avoid this? one way I can think about is to modify the Observable to push content one by one(by using 'lock'), then the performance must be hurts lot.
Thanks.