0

I want to solve a data race issue in my program. I thought about using RXJava's Single but due to the way the program runs, it's uncertain whether the receiver will be able to subscribe to the Single before it emits data.

I was unable to find information if the Single observable implements something like a retro-emit(?) - I don't know how to call that. Thanks in advance.

AdamK
  • 11
  • 1
  • 2
    Depends on how the `Single` "creates" the data. Cold sources will only emit if they have an observer. Hot Singles (in your area) will remember the item they receive and will replay it to future observers. – akarnokd Aug 24 '23 at 20:12
  • So how can I make sure that I have a Hot Single :) ? In my implementation the Single would be emitting a simple boolean value after certain async operations are finished in one class, then the other class would react to that accordingly. – AdamK Aug 24 '23 at 20:16
  • For a hot source, you will need to subscribe before the value is emitted. Simple. Alternatively you can buffer the emitted element since there’s only going to be one. [What are the Hot and Cold observables?](https://stackoverflow.com/questions/2521277/what-are-the-hot-and-cold-observables) – Abhijit Sarkar Aug 24 '23 at 20:22

0 Answers0