I have a question regarding how to configure an c# Reactive ReplaySubject so that it exhibits the following behavior:
- When OnNext() is called, and there is no subscriber yet, the item handed to OnNext() should be cached inside the ReplaySubject.
- When there is at least one cached item, and a consumer subscribes to the ReplaySubject, it receives all cached items. After an Item is received, it should be removed from the ReplaySubject's cache and not returned anymore after a second consumer subscribes.
- When two or more consumers subscribed to the ReplaySubject before an item is added. All consumers should get the item that is passed to OnNext() when it is called. (This is not super important, it would also be ok if only the first or last subscriber gets the item)
Within the ReplaySubject's constructor, I can only find parameters that constraint the time an item is retained or the amount of items that are retained.
Here a little bit more context as to why I want to achieve the described behavior. I am working on a mobile phone app that communicates with a bluetooth device. The bluetooth device can send notifications which the app receives (BT Gatt Notification). After the app receives a bunch of notifications, it merges those notification into a message which is passed to the ReplaySubject and then processed by the subscribers.
Any hints regarding how to achieve the behavior described above or an alternative solution that is more fit to solve my use case are highly appreciated.