Replaying
The replay() operator is a powerful way to hold onto previous emissions and re-emit them when a new Observer comes in. It returns ConnectableObservable, which both multicasts emissions and emits previous emissions. It emits the cached values immediately when a new Observer subscribes so it is caught up, and then it fires current emissions from that point forward.
Let's start with a replay() with no arguments. This will replay all previous emissions to tardy observers and then emit current emissions as soon as the tardy Observer is caught up. If we use Observable.interval() to emit every second, we can call replay() on it to multicast and replay previous integer emissions. Since replay() returns ConnectableObservable, let's use ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access