0

Imagine you have a replay observable, created through one of the Replay overloads. Is there a variant of Replay that produces a replay observable with a method that lets me remove an item/message/element from the replay buffer?

I need the replay observable in order to avoid a race condition: two observables A and B produce related messages. If A produces a message m, then B may follow suit with a corresponding message m' (but that's optional).
In order to filter out m' from all of B's messages, the subscriber to A registers a subscriber with B (filtered for the exact m' message), since only when m is received will the program be able to predict what a potentially incoming m' will look like.

However, sometimes m' arrives even before the subscriber to A was scheduled to run, meaning there is no subscriber for m' registered yet. I can solve this by wrapping B as a replay observable, but I want to be able to clean up processed messages from the replay buffer, because I know each of B's messages will be processed by exactly one subscriber.

derabbink
  • 2,419
  • 1
  • 22
  • 47

1 Answers1

0
var result = foo.Replay().Where(x => x != skip);
Aron
  • 15,464
  • 3
  • 31
  • 64
  • I think this will not solve my problem: My original observable is ongoing, meaning the first replay-wrapper around it will not be disposed of, until all of its subscribers are gone. So if I just keep on adding layers of filtered replay-wrappers, the inner layers will accumulate forever. – derabbink Aug 20 '13 at 11:31
  • Actually, just re-read your problem. Have you considered using `IObservable.Zip()`? – Aron Aug 20 '13 at 13:09
  • I considered, then discarded the idea :) For `Zip`to work, i need to *always* have an `m'` (for each `m`). But the `m'` is optional – derabbink Aug 20 '13 at 15:26
  • When you say optional, does the consumer know if it is optional? Because the `m'` subscription could then be kludged to return a null `m'` when it isn't required...Or even use a different observer/subscriber pair, then join them up again... – Aron Aug 21 '13 at 01:33
  • The incoming `m` will only allow to predict how to identify/filter out the corresponding `m'`, should one arrive. It can't be used predict whether or not it *will* come – derabbink Aug 21 '13 at 08:12