I am developing a solution where changes occur at high rate for example for a user. What I need is to record each change, delay notification and then return distinct changes e.g user ids for users that had been changed. I have come up with the following code using rx:
private Subject<int> userEventSubject= new Subject<int>();
userEventSubject
.Buffer(EVENT_BUFFER_DELAY)
.Where(buffer => buffer.Count > 0)
.Subscribe(OnEventBufferProcess);
This seem to work correctly and I get all the values that were added by
userEventSubject.OnNext(userId);
My question is: Can I distinct the changes e.g when having multiple OnNext with same user id value I don't want the resulting buffer to contain duplicates. Of course I can distinct values in the Subscribe handler but I wondered if this can be done on rx level? I tried the distinct method but would still get all the values.
Since all I want is to track changes made during the delay, return to Subscribe handler and start over, do I need to clear the userEventSubject?