Tiny note about Replay Subject
Today one of my co-workers sent me a pull request with regard to tracking, and he used this ReplaySubject class from RxJava for it. I thought this class can be pretty helpful especially when you consider seriously about network error handling and the behavior of the app after users’ network connection gets settled.
※ If you are familiar with the concept of reactive programming then you either already know this class or you can grasp the idea of it by just seeing the diagram above or reading the example usage on the javadoc.
According to the RxJava javadoc, ReplaySubject is a
Subject that buffers all items it observes and replays them to any Observer that subscribes.
As the statement above explains almost everything, you can replay all the items that have come into the stream to the observers that subscribes this subject.
This may be helpful when you want to ‘replay’ or buffer user actions or results of the user actions happened without any network connection, and do something about it when the users’ network connection restores.
I remember someone saying that RxJava is kind of hard to fully make use of it as it has a lot of functionality and sometimes it is not very easy to understand, but it is also true that as you learn it, you will gain more and be able to make use of it more wisely.