Another great way to implement Hot Observables is Subject. Basically, it is a combination of Observable and Observer, as it has many common behaviors to both Observables and Observers. Like Hot Observables, it maintains an internal Observer list and relays a single push to every Observer subscribed to it at the time of emission.
So, let's take a look at what Subject has to offer us. And why is it called a combination of Observables and Observers? Please refer to the following points:
- It has all the operators that Observable should have.
- Like Observer, it can listen to any value emitted to it.
- After Subject is completed/errored/unsubscribed, it cannot be reused.
- The most interesting point is that it passes values through itself. ...